When we using a transation from System.Transactions (creating TransationScope for an instance) by default all Sql-connections (System.Data.SqlClient.SqlConnection) (but is't also the true for Oracle.DataAccess.OracleConnection) are enlisted on opening.
That's called auto-enlistment. Nice feature. But it can be turned off throught a connection string's parameter (enlist=false). In that case connection being opened wouldn't be enlisted.
But it can be enlisted manually later.
So my question is: for some given SqlConnection's instance how can I determine whether that connection is enlisted or not (into an System.Transaction).
I can look at connection string for the parameter. But this won't do because as I said connection could be enlisted manually.
R – How to determine whether SqlConnection is enlisted into a System.Transactions’ tx or not
.net-2.0ado.netmsdtcnettransactions
Related Topic
- C# – TransactionScope automatically escalating to MSDTC on some machines
- R – Determine whether the transaction is DTC transaction or not when debugging
- C# – How to remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning
- Sql – How do distributed transactions behave with multiple connections to the same DB in a threaded environment
- C# – Under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction
- C# – How to turn a C# object into a JSON string in .NET
Best Answer
The framework doesn't appear to allow that.
Perhaps we could discuss why you need to know this information? The TransactionScopeOptions give you some flexibility about when to create transactions.
However, refusing "no" for an answer, a little source browsing later and I've created this code, which DOES work. Note, that this code could cease to function at anytime with patches to the framework!!!!
Again, this is making use of private variables and internal classes within the .NET framework. While it works today, it may not tomorrow.