Passing a Transaction Between the Application Program and the RM Proxy
A database resource manager that used the standard ODBC syntax for passing a transaction between the application program and the RM proxy would work as follows:
The application initiates the transaction by calling the OLE Transactions BeginTransaction method. In response, the application receives a transaction object that represents the transaction.
-
The application passes the transaction to the RM proxy by calling the ODBC SQLSetConnectOption statement. The parameters to the SQLSetConnectOption statement include the ODBC connection handle and the transaction object.
-
The RM proxy marshals the transaction object by calling the OLE Transactions export interface. The RM proxy places the marshaled transaction object into a request message and sends the request message to the resource manager.
-
The resource manager takes the marshaled transaction object from the request message and unmarshals it by calling the OLE Transactions ITransactionImport interface. The import interface returns a transaction object to the resource manager.
-
The resource manager enlists in the imported transaction object. By enlisting on the transaction, the resource manager enrolls itself in the two-phase commit protocol.
-
The application program performs normal resource manager operations such as inserting, updating, or deleting records in a relational database. These operations are performed under the protection of the transaction.
-
When the application program calls Commit, MS DTC uses the two-phase commit protocol to coordinate commitment of the transaction. MS DTC will invoke the resource manager at phase one to prepare the transaction and at phase two to commit the transaction.
You may choose your own application program interface for propagating transactions from the application program to your resource manager. For example, Microsoft SQL Server associates the transaction with the ODBC or DB-Library database connection. The SQLSetConnectOption function is used with ODBC connections The dbenlisttrans function is used with DB-Library connections. Once a transaction is associated with a connection, it remains associate with the connection until the next SQLSetConnectOption or dbenlisttrans call.
Other alternatives are possible. For example, rather than associating a transaction with a connection, you could insist that the transaction be passed as a parameter to every resource manager call. If you do this, you should ensure that you only export each transaction once, when it is first used.