Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
In diesem Thema erfahren Sie, wie Sie Transaktionen beim Programmieren mit dem OLE DB-Anbieter für SQL Server 2005 Compact Edition (SQL Server Compact Edition) verwenden.
Beispiel
Im folgenden Beispiel wird gezeigt, wie Sie eine Transaktion mithilfe des OLE DB-Anbieters für SQL Server Compact Edition erstellen und ausführen. Das Beispiel enthält nur die transaktionsbezogenen Abschnitte der InsertEmployeeInfo-Funktion.
///////////////////////////////////////////////////////////////////////
// The following steps have been removed from this sample.
// 1) Verify that IDBCreateSession exists on the datasource.
// 2) Create a session object.
// 3) Set up information necessary to open a table by using an index.
// 4) Set the binding properties and create the accessor.
///////////////////////////////////////////////////////////////////////
// Begins a new local transaction to insert employee data
hr = pITxnLocal->StartTransaction(ISOLATIONLEVEL_READCOMMITTED, 0, NULL, NULL);
// Error handling for failed creation of the transaction
if(FAILED(hr))
{
goto Exit;
}
///////////////////////////////////////////////////////////////////////
// The code to prepare the sample data to insert has been removed.
//
///////////////////////////////////////////////////////////////////////
hr = pIRowsetChange->InsertRow(DB_NULL_HCHAPTER, hAccessor, pData, prghRows);
// Error handling that aborts the transaction on failure
if (FAILED(hr))
{
goto Abort;
}
// Get the row data.
hr = pIRowset->GetData(rghRows[0], hAccessor, pData);
if(FAILED(hr))
{
goto Abort;
}
// Check the status.
if (DBSTATUS_S_OK != *(DBSTATUS*)(pData+prgBinding[dwPhotoCol].obStatus))
{
hr = E_FAIL;
pIRowset->ReleaseRows(1, prghRows, NULL, NULL, NULL);
goto Abort;
}
///////////////////////////////////////////////////////////////////////
// Perform a transactional task here.
///////////////////////////////////////////////////////////////////////
// Commit the transaction by using ITransactionLocal::Commit
// to insert the data.
if (pITxnLocal)
{
pITxnLocal->Commit(FALSE, XACTTC_SYNC, 0);
}
goto Exit;
// Calling goto Abort uses the ITransactionLocal::Abort
// to cancel the transaction.
Abort:
// Cancel the transaction.
if (pITxnLocal)
{
pITxnLocal->Abort(NULL, FALSE, FALSE);
}
Exit:
// Release the resources.