Share via


Opening an XA Connection

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

When an ODBC connection is initially obtained, it is in a local transaction state. To enlist in a distributed transaction, an application sets the connection attribute SQL_ENLIST_IN_DTC and passes in a non-null transaction pointer. The application remains in the distributed application state until it sets the connection attribute SQL_ENLIST_IN_DTC with a null transaction pointer.

When the connection changes from the local transaction state to the distributed transaction state, the resource manager proxy should call IDtcToXaMapper::RequestNewResourceManager to obtain a resource manager cookie for the resource manager. (In this case, the resource manager is defined by the Data Source Name [DSN].)

Note

Driver implementers should not use the same resource manager 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 transaction manager that contains the DSN and the name of the client DLL. Then the XA transaction manager checks to see whether it already has an XA connection to the resource manager with the same DSN. If not, the XA transaction manager does the following:

  1. Loads the client DLL.

  2. Gets the address of the GetXaSwitch function.

  3. Calls the GetXaSwitch function to obtain the address of the XA switch data structure implemented by the resource manager proxy.

  4. Calls the xa_open_entry function to open an XA connection with the resource manager.

When the resource manager's xa_open_entry function is called, the DTC transaction manager passes in the DSN as the OPEN_STRING. The implementation of the xa_open_entry 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 wherever it would have been stored at the time the DSN was created.

If the RequestNewResourceManager method call succeeds, the following are true:

  • An XA connection is open from the XA transaction manager to the resource manager proxy.

  • A resource manager cookie is mapped to a DSN entry, which is available in the mapping table.