![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
A serviced component with transaction attribute Required connects to SQL Server via an inline coded connection string and does some work in the database. |

|
It also creates and calls another component with transaction Required (so joins the current txn) that does work in the same or another SQL instance. Out of curiosity, how does COM+ know that all this belongs to ONE logical transaction. What logic makes sure that the Open methods of ADO.NET (or ADO?) of the components are communicated to COM+ so that it knows what database connections are enlisted in the txn? |
#3
| |||
| |||
|
You might want to avoid hardcoding your connection strings ![]() |
|
Finally, the reason why the ADO.NET connections magically join this transaction is because the ADO.NET providers that support distributed transactions explicitily check when you request a connection if they are being called from inside a COM+ context that is associated with a transaction, and if so, join the connection to the transaction before handing it back to your code for using it. |
#4
| |||
| |||
|
|
That helps! But still sounds a bit like magic. Exactly when does COM+ peek what SQL Server is gonna be used (and how), or perhaps the other way round, when does the ADO.NET connection tell COM+? |
#5
| |||
| |||
|
|
Hi Hans, That helps! But still sounds a bit like magic. Exactly when does COM+ peek what SQL Server is gonna be used (and how), or perhaps the other way round, when does the ADO.NET connection tell COM+? That last part is exactly what happens. The Data Access Providers are the ones that know what server they need to open the connection to and interact (alongside the database server) with the DTC to enroll the connection into the distributed transaction. In the case of, for example, SqlClient, exactly where this happens is fairly underneath the covers, since the connection pooling support has to be aware of this happening (a connection that was joined to a transaction cannot be joined to another transaction until that one is done, so this changes the basic criteria for handling out connections from the pool). If you want to know exactly where this happens, check out the code for the TryGetResourceFromContext() method of the System.Data.SqlClient.ConnectionPool class, which basically uses the System.EnterpriseServices.ContextUtil class to check for the COM+ context and verify if it has a transaction associated with it. Also, you might be interested in knowing that there are two other options that control how this process happens: - If you don't want your connections to join a DTC transaction available in the COM+ context, you can simply especify "Enlist=false" as part of the connection string - You can also manually join a sql connection to a DTC transaction via the EnlistDistributedTransaction() method of the SqlConnection class. -- Tomas Restrepo tomasr (AT) mvps (DOT) org http://www.winterdom.com/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |