.net 事务范围块第二个事务
在我的应用程序中,我有以下模式:
using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
{
Function1();
Function2();
Function3();
}
我的问题是 Function2 调用连接到另一个数据库的另一个函数......并且事务变得分布式,并且我得到一个异常。
代码中是否有任何方法可以进行不属于当前事务的数据库调用?我在 Function2 中的代码只执行读取操作...所以我不想成为当前事务的一部分。
谢谢,拉杜
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
function2
周围,您可以使用TransactionScopeOption.RequiresNew
创建一个新事务,从而强制它进入自己的单独事务。由于该事务中仅使用一种资源(另一个数据库),因此不应进行分布式。Around
function2
you could create a new transaction withTransactionScopeOption.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.