Transaction Scope and multithread

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
robymes
Posts: 29
Joined: Tue 09 Sep 2008 09:46

Transaction Scope and multithread

Post by robymes » Mon 09 Mar 2009 09:34

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 10 Mar 2009 13:30

Thank you for the report, we will investigate this problem.
I will let you know about the results.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 17 Mar 2009 08:29

This problem is fixed, the fix will be included in the upcoming build.

browniepoints
Posts: 2
Joined: Tue 17 Mar 2009 19:32

Post by browniepoints » Tue 17 Mar 2009 21:24

Wondering what was happening there. I thought TransactionScope created a ThreadStatic "ambient" transaction.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 18 Mar 2009 14:36

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.

Post Reply