How to: Use Microsoft Distributed Transaction Coordinator (ODBC)

新建日期: 2006 年 4 月 14 日

To update two or more SQL Servers by using MS DTC

  1. Connect to MS DTC by using the MS DTC OLE DtcGetTransactionManager function. For information about MS DTC, see Microsoft Distributed Transaction Coordinator.

  2. Call SQLDriverConnect once for each Microsoft® SQL Server™ connection you want to establish.

  3. Call the MS DTC OLE ITransactionDispenser::BeginTransaction function to begin an MS DTC transaction and obtain a Transaction object that represents the transaction.

  4. Call SQLSetConnectAttr one or more times for each ODBC connection you want to enlist in the MS DTC transaction. SQLSetConnectAttr second parameter must be SQL_ATTR_ENLIST_IN_DTC and third parameter must be the Transaction object (obtained in Step 3).

  5. Call SQLExecDirect once for each SQL Server you want to update.

  6. 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 SQLSetConnectAttr with SQL_DTC_DONE.

ms403286.note(zh-cn,SQL.90).gif注意:
You can also call SQLSetConnectAttr and SQLExecDirect in turn for each SQL Server instead of calling them as suggested earlier in Steps 4 and 5.

请参阅

其他资源

Performing Transactions (ODBC) (How to)

帮助和信息

获取 SQL Server 2005 帮助