Using Microsoft Distributed Transaction Coordinator
The SQL Server driver supports Microsoft Distributed Transaction Coordinator (MS DTC) and MS DTC transactions.
To update two or more SQL Servers using MS DTC
-
Connect to MS DTC using the MS DTC OLE DtcSelectTransactionManager function. For information about MS DTC, see the Guide to Microsoft Distributed Transaction Coordinator.
-
Call SQLDriverConnect once for each SQL Server connection you want to establish.
-
Call the MS DTC OLE ITransactionDispenser::BeginTransaction function to begin an MS DTC transaction and obtain a Transaction object that represents the transaction.
-
Call SQLSetConnectOption one or more times for each ODBC connection you want to enlist in the MS DTC transaction. SQLSetConnectOption must be called with an fOption of SQL_COPT_SS_ENLIST_IN_DTC and a vParam of the Transaction object (obtained in step 3).
-
Call SQLExecDirect once for each SQL Server you want to update.
-
Call the MS DTC OLE ITransaction::Commit function to commit the MS DTC transaction. The Transaction object is no longer valid.
To perform a series of MS DTC transactions, repeat steps 3 through 6.
To release the reference to the Transaction object, call the MS DTC OLE ITransaction::Return function.
To use an ODBC connection with an MS DTC transaction, and then use the same connection with a local SQL Server transaction, call SQLSetConnectOption with a vParam of SQL_DTC_DONE.
Note You can also call SQLSetConnectOption and SQLExecDirect in turn for each SQL Server instead of calling them as suggested in steps 4 and 5 above.