INFO: Connections May Not Participate in MTS/COM+ Transactions When You Use OLE DB Directly (240037)



The information in this article applies to:

  • Microsoft Transaction Server 2.0

This article was previously published under Q240037

SUMMARY

When you use OLE DB directly, database connections may not be automatically enlisted in Microsoft Transaction Server (MTS)/COM+ transactions. To make OLE DB perform transaction enlistment for you, you must use a provider through the OLE DB services component. If you use the Microsoft OLE DB provider for ODBC (MSDASQL), ODBC does the enlistment for you. However, if you use a native provider such as the provider for SQL Server, and you are not using OLE DB services, enlistment does not occur.

NOTE: This problem does not occur with ActiveX Data Objects (ADO) because ADO automatically uses the services component with OLE DB data connections.

MORE INFORMATION

When consumers use the Microsoft OLE DB provider for ODBC (MSDASQL), they can call the CoCreateInstance function on CLSID_MSDASQL directly, and ODBC automatically enlists in your MTS transaction. When you use a native OLE DB provider, to automatically enlist in an MTS transaction, you must call CoCreateInstance on CLSID_MSDAINITIALIZE, which is the OLE DB services component. You must then request an IID_IDataInitialize pointer and call CreateDBInstance with the CLSID of your provider to instantiate your provider. If you do not use ODBC and MSDAINITIALIZE, the database work is not automatically enlisted in an MTS transaction.

When you use the Microsoft OLE DB provider for ODBC, consumers create a provider's data source object either through the root enumerator or by passing the provider's CLSID to CoCreateInstance, as in the following code example:
// Create an instance of CLSID_MSDASQL.
CoCreateInstance(CLSID_MSDASQL, NULL, CLSCTX_INPROC_SERVER, 
                 IID_IDBInitialize,(void**)&pIDBInitialize);
				
In order for OLE DB to handle enlistment in MTS/COM+ transactions, you must use OLE DB services. To ensure that all modifications that are performed by an MTS object against the data source are enlisted in the MTS transaction, you must instantiate your provider through the OLE DB Services component. The following code illustrates this:
// Create an instance of the OLE DB Initialization Component.
CoCreateInstance(CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, 
   IID_IDataInitialize, (void**)&pIDataInitialize) ;

// Create an instance of CLSID_MSDASQL with supported services.
pIDataInitialize->CreateDBInstance(CLSID_MSDASQL, NULL, 
   CLSCTX_INPROC_SERVER, NULL, IID_IDBInitialize, 
   (IUnknown**)&pIDBInitialize);
				

Modification Type:MajorLast Reviewed:6/12/2001
Keywords:kbDSupport kbinfo kbTransaction KB240037