Get TransactionScope to work with async / await

In .NET Framework 4.5.1, there is a set of new constructors for TransactionScope that take a TransactionScopeAsyncFlowOption parameter. According to the MSDN, it enables transaction flow across thread continuations. My understanding is that it is meant to allow you to write code like this: // transaction scope using (var scope = new TransactionScope(… , TransactionScopeAsyncFlowOption.Enabled)) … Read more

SQL Server: Isolation level leaks across pooled connections

The connection pool calls sp_resetconnection before recycling a connection. Resetting the transaction isolation level is not in the list of things that sp_resetconnection does. That would explain why “serializable” leaks across pooled connections. I guess you could start each query by making sure it’s at the right isolation level: if not exists ( select * … Read more

Under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction?

I’ve done some tests since asking this question and found most if not all answers on my own, since no one else replied. Please let me know if I’ve missed anything. Q1: Is connection automatically enlisted in transaction? Yes, unless enlist=false is specified in the connection string. The connection pool finds a usable connection. A … Read more

TransactionScope automatically escalating to MSDTC on some machines?

SQL Server 2008 can use multiple SQLConnections in one TransactionScope without escalating, provided the connections are not open at the same time, which would result in multiple “physical” TCP connections and thus require escalation. I see some of your developers have SQL Server 2005 and others have SQL Server 2008. Are you sure you have … Read more