Using the ASE ODBC driver to participate in Distributed Transactions

This feature is supported only on Microsoft Windows and requires that Microsoft Distributed Transaction Coordinator (MS DTC) be the transaction coordinator managing two-phase commit.

Sybase supports all of the following programming models:


Programming for MS DTC

StepsTo program using Microsoft Distributed Transaction Coordinator (MS DTC)

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

  2. Call SQLDriverConnect or SQLConnect once for each Sybase ASE connection you want to establish.

  3. Call the ITransactionDispenser::BeginTransaction function to begin an MS DTC transaction and to obtain an OLE 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 must be called with an attribute of SQL_ATTR_ENLIST_IN_DTC and a ValuePtr of the Transaction object (obtained in step 3).

  5. Call SQLExecDirect one or more times for each insert or update SQL statement.

  6. Call the 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 ITransaction::Release function.To use an ODBC connection with an MS DTC transaction and then use the same connection with a local ASE Server transaction, call SQLSetConnectAttr with a ValuePtr of SQL_DTC_DONE to unenlist the connection from the transaction.

NoteAlso, you can call SQLSetConnectAttr and SQLExecDirect separately for each ASE Server instead of calling them as suggested in steps 4 and 5.


Programming components deployed in Sybase EAServer, MTS, or COM+

The following procedure describes how to create components that participate in Distributed Transactions in Sybase EAServer, MTS, or COM+.

StepsTo program components deployed in Sybase EAServer, MTS, or COM+

  1. Call SQLDriverConnect once for each Sybase ASE connection you want to establish.

  2. Call SQLExecDirect one or more times for each insert or update SQL statement.

  3. Deploy your component to MTS and configure the transaction attributes as needed.

The transaction coordinator creates a distributed transaction as needed, and the component that uses the ASE ODBC driver automatically enlists in the global transaction. Then the transaction coordinator will commit or roll back the distributed transaction.


Connection properties for Distributed Transaction support

The following describes the Connection properties:

WARNING! Enlistment with SQLSetConnectAttr returns a SQL_ERROR if the connection has already begun a local transaction either by using SQLSetConnectAttr with the SQL_AUTOCOMMIT_OFF or by executing the BEGIN TRANSACTION statement explicitly using SQLExecDirect.