Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
van toepassing op:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
Consumenten van SQL Server Native Client OLE DB-aanbieders kunnen de methode ITransactionJoin::JoinTransaction gebruiken om deel te nemen aan een gedistribueerde transactie die wordt gecoördineerd door Microsoft Distributed Transaction Coordinator (MS DTC).
MS DTC stelt COM-objecten bloot die clients in staat stellen gecoördineerde transacties te initiëren en eraan deel te nemen via meerdere verbindingen naar diverse datastores. Om een transactie te initiëren gebruikt de consument van de SQL Server Native Client OLE DB-provider de MS DTC ITransactionDispenser-interface. Het BeginTransaction-lid van ITransactionDispenser geeft een referentie terug op een gedistribueerd transactieobject. Deze referentie wordt doorgegeven aan de SQL Server Native Client OLE DB-provider via JoinTransaction.
MS DTC ondersteunt asynchrone commit- en abort-acties bij gedistribueerde transacties. Voor melding van asynchrone transactiestatus implementeert de consument de ITransactionOutcomeEvents-interface en verbindt deze interface met een MS DTC-transactieobject.
Voor gedistribueerde transacties implementeert de SQL Server Native Client OLE DB-provider ITransactionJoin::JoinTransaction-parameters als volgt.
| Parameter | Description |
|---|---|
| punkTransactionCoord | Een verwijzing naar een MS DTC-transactieobject. |
| IsoLevel | Genegeerd door de SQL Server Native Client OLE DB-provider. Het isolatieniveau voor MS DTC-gecoördineerde transacties wordt bepaald wanneer de consument een transactieobject van MS DTC verkrijgt. |
| IsoFlags | Moet 0 zijn. De SQL Server Native Client OLE DB-provider geeft XACT_E_NOISORETAIN terug als een andere waarde door de consument wordt opgegeven. |
| POtherOptions | Als het niet NULL is, vraagt de SQL Server Native Client OLE DB-provider het options-object aan via de interface. De SQL Server Native Client OLE DB-provider geeft XACT_E_NOTIMEOUT terug als het ulTimeout-lid van het options-object niet nul is. De SQL Server Native Client OLE DB-provider negeert de waarde van het szDescription-lid. |
Dit voorbeeld coördineert transacties met behulp van MS DTC.
// Interfaces used in the example.
IDBCreateSession* pIDBCreateSession = NULL;
ITransactionJoin* pITransactionJoin = NULL;
IDBCreateCommand* pIDBCreateCommand = NULL;
IRowset* pIRowset = NULL;
// Transaction dispenser and transaction from MS DTC.
ITransactionDispenser* pITransactionDispenser = NULL;
ITransaction* pITransaction = NULL;
HRESULT hr;
// Get the command creation interface for the session.
if (FAILED(hr = pIDBCreateSession->CreateSession(NULL,
IID_IDBCreateCommand, (IUnknown**) &pIDBCreateCommand)))
{
// Process error from session creation. Release any references and
// return.
}
// Get a transaction dispenser object from MS DTC and
// start a transaction.
if (FAILED(hr = DtcGetTransactionManager(NULL, NULL,
IID_ITransactionDispenser, 0, 0, NULL,
(void**) &pITransactionDispenser)))
{
// Process error message from MS DTC, release any references,
// and then return.
}
if (FAILED(hr = pITransactionDispenser->BeginTransaction(
NULL, ISOLATIONLEVEL_READCOMMITTED, ISOFLAG_RETAIN_DONTCARE,
NULL, &pITransaction)))
{
// Process error message from MS DTC, release any references,
// and then return.
}
// Join the transaction.
if (FAILED(pIDBCreateCommand->QueryInterface(IID_ITransactionJoin,
(void**) &pITransactionJoin)))
{
// Process failure to get an interface, release any references, and
// then return.
}
if (FAILED(pITransactionJoin->JoinTransaction(
(IUnknown*) pITransaction, 0, 0, NULL)))
{
// Process join failure, release any references, and then return.
}
// Get data into a rowset, then update the data. Functions are not
// illustrated in this example.
if (FAILED(hr = ExecuteCommand(pIDBCreateCommand, &pIRowset)))
{
// Release any references and return.
}
// If rowset data update fails, then terminate the transaction, else
// commit. The example doesn't retain the rowset.
if (FAILED(hr = UpdateDataInRowset(pIRowset, bDelayedUpdate)))
{
// Get error from update, then abort.
pITransaction->Abort(NULL, FALSE, FALSE);
}
else
{
if (FAILED(hr = pITransaction->Commit(FALSE, 0, 0)))
{
// Get error from failed commit.
//
// If a distributed commit fails, application logic could
// analyze failure and retry. In this example, terminate. The
// consumer must resolve this somehow.
pITransaction->Abort(NULL, FALSE, FALSE);
}
}
if (FAILED(hr))
{
// Update of data or commit failed. Release any references and
// return.
}
// Un-enlist from the distributed transaction by setting
// the transaction object pointer to NULL.
if (FAILED(pITransactionJoin->JoinTransaction(
(IUnknown*) NULL, 0, 0, NULL)))
{
// Process failure, and then return.
}
// Release any references and continue.