Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net detect distributed transaction

In my application I use the following pattern for calling the DB:

    //do a transaction 
using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
{
    OperationOnDb1();

    //when we open the connection to the “other db” in this call, the transaction would become distributed
    OperationOnDb2();

    //transaction is now distributed
    transaction.Complete();
}

The problem is that Operation1 and Operation2 90% of the time use the same db ... but there are cases (bugs) when they use two DBs. I want to get an exception if the transaction becomes distributed.

How can I detect if the transaction is promoted to a distributed transaction?

Thanks, Radu

like image 468
Radu D Avatar asked Feb 10 '26 22:02

Radu D


1 Answers

You can also have a look at the following event

TransactionManager.DistributedTransactionStarted Event

like image 68
Hps Avatar answered Feb 13 '26 17:02

Hps