开发者

.net transaction scope block second transaction

开发者 https://www.devze.com 2023-01-24 03:49 出处:网络
In my application I have the following pattern: using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))

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 开发者_Go百科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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消