Page 1 of 1

Transaction Scope and multithread

Posted: Mon 09 Mar 2009 09:34
by robymes
Hello,
I have a WCF service and I have a problem with TransactionScope when connection is not in direct mode (Direct=False).

I have something like this:

Code: Select all

TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
transactionOptions.Timeout = new TimeSpan(0, 0, 30);
using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions))
{
    using (SomeObjectContext someObjectContext = new SomeObjectContext())
    {
        ...
        someObjectContext.SaveChanges();
    }
transactionScope.Complete();
}
when there are multiple concurrent threads it works only in direct=true connection mode, in direct=false connection mode all the transactions fail. It seems that in direct=false connection mode transactions are merged in some way even if TransactionScopeOption.RequiresNew flag.
Thanks for your support.

Posted: Tue 10 Mar 2009 13:30
by AndreyR
Thank you for the report, we will investigate this problem.
I will let you know about the results.

Posted: Tue 17 Mar 2009 08:29
by AndreyR
This problem is fixed, the fix will be included in the upcoming build.

Posted: Tue 17 Mar 2009 21:24
by browniepoints
Wondering what was happening there. I thought TransactionScope created a ThreadStatic "ambient" transaction.

Posted: Wed 18 Mar 2009 14:36
by AndreyR
You are right, TransactionScope with RequireNew creates a new transaction for every thread from your example.
The problem was associated with Transaction IDs comparison, not with TransactionScope itself.