Radu D
Radu D

Reputation: 3555

.net transaction scope block second transaction

In my application I have the following pattern:

using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
{
    Function1();
    Function2();
    Function3();
}

My problen is that Function2 calls another function that connects to another DB ... and the transaction becomes distributed and I get an exception.

Is there any way in the code in which I can make a db call that is not part of the current transaction? My code in Function2 does just a read ... so I don't want to be part of current transaction.

Thanks, Radu

Upvotes: 2

Views: 755

Answers (1)

Richard
Richard

Reputation: 109005

Around function2 you could create a new transaction with TransactionScopeOption.RequiresNew, thus forcing it into its own separate transaction. Since only one resource (the other database) will be used in that transaction is shouldn't become distributed.

Upvotes: 3

Related Questions