Platform SDK: Transaction Server

Transaction States

When the ODBC connection is initially obtained, it is in a local transaction state. An application enlists in a distributed transaction by setting the connection attribute SQL_ENLIST_IN_DTC and passing in a non-null transaction pointer. It remains in that state until the application sets the connection attribute SQL_ENLIST_IN_DTC with a null transaction pointer.

Transaction State Machine

When the connection transitions from the local transaction state to the distributed transaction state, the ODBC driver should call the RequestNewResourceManager method to obtain a RM cookie for the resource manager. The resource manager in this case is defined by the Data Source Name (DSN).

Note Driver implementers shouldn’t use the same RM cookie for two separate ODBC connections if the DSN on both connections is the same.

Calling RequestNewResourceManager results in a message from the DTC proxy to the XA TM. When the XA TM receives a message that contains the DSN and the name of the client DLL, it first checks to see if it already has an XA connection to the resource manager with the same DSN. If not, then the XA TM does the following:

  1. Loads the client DLL.
  2. Gets the address of the GetXaSwitch function.
  3. Calls the GetXaSwitch function to obtain the XA_Switch.
  4. Calls the xa_open function to open an XA connection with the resource manager.

Note In step 4, when the RM's xa_open function is called, the DTC TM passes in the DSN as the OPEN_STRING. The implementation of the xa_open function should create the appropriate OPEN_STRING based on the DSN. For example, if it needs any user id or security information, it can get that from the registry or anywhere else where it would have been stored at the time the DSN was created.

When the RequestNewResourceManager method call returns with a success two things are TRUE:

  1. There is an XA Connection open from the XA TM to the ODBC driver for the resource manager.
  2. There is an RM cookie to DSN entry available in the mapping table which maps an RM cookie to a DSN.