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:
Applications using MS DTC directly
Applications using Sybase Enterprise Application Server (EAServer, also known as Jaguar)
Applications using Microsoft Transaction Server (MTS) or (COM+)
To program using Microsoft Distributed Transaction
Coordinator
(MS DTC)
Connect to MS DTC by using the DtcGetTransactionManager function. For information about MS DTC, see the relevant Microsoft Distributed Transaction Coordinator documentation.
Call SQLDriverConnect or SQLConnect once for each Sybase ASE connection you want to establish.
Call the ITransactionDispenser::BeginTransaction function to begin an MS DTC transaction and to obtain an OLE Transaction object that represents the transaction.
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).
Call SQLExecDirect one or more times for each insert or update SQL statement.
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.
Also, you can call SQLSetConnectAttr and SQLExecDirect separately
for each ASE Server instead of calling them as suggested in steps
4 and 5.
The following procedure describes how to create components that participate in Distributed Transactions in Sybase EAServer, MTS, or COM+.
To program components deployed in Sybase EAServer,
MTS, or COM+
Call SQLDriverConnect once for each Sybase ASE connection you want to establish.
Call SQLExecDirect one or more times for each insert or update SQL statement.
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.
The following describes the Connection properties:
Distributed Transaction Protocol (DistributedTransactionProtocol) – To specify the protocol used to support the distributed transaction, XA Interface standard or MS DTC OLE Native protocol, select the Distributed Transaction Protocol in the ODBC Data Source Dialog or pass the property DistributedTransactionProtocol = OLE native protocol in the connection string. The default is XA.
Tightly Coupled Transaction (TightlyCoupledTransaction) – When you have a distributed transaction using two resource managers that point to the same ASE server, you have a situation called a "Tightly Coupled Transaction." Under these conditions, if you do not set this property to 1, the Distributed Transaction will fail.
To summarize, if you open two database connections to the same ASE server and then enlist these connections in the same distributed transaction, you must set TightlyCoupledTransaction=1.
To set this property select the Tightly Coupled Transaction in the ODBC Data Source dialog, or pass the property TightlyCoupledTransaction=1 in the connection string.
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.