.net 检测分布式事务 [英] .net detect distributed transaction

查看:60
本文介绍了.net 检测分布式事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用以下模式调用数据库:

//做一个交易使用 (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required)){OperationOnDb1();//当我们在此调用中打开与其他数据库"的连接时,事务将变为分布式OperationOnDb2();//交易现在已分发交易.完成();}

问题是 Operation1 和 Operation2 90% 的时间使用相同的 db ...但是当它们使用两个 DB 时也存在一些情况(错误).如果事务被分发,我想得到一个异常.

如何检测事务是否提升为分布式事务?

谢谢,拉杜

解决方案

你也可以看看下面的事件

TransactionManager.DistributedTransactionStarted 事件

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

解决方案

You can also have a look at the following event

TransactionManager.DistributedTransactionStarted Event

这篇关于.net 检测分布式事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆