一个TransactionScope内隔离ADO.NET连接和事务 [英] Isolated ADO.NET connection and transaction within a transactionscope

查看:123
本文介绍了一个TransactionScope内隔离ADO.NET连接和事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我有一个ASP.NET MVC应用程序中使用的行为过滤器,它包装控制器动作在一个TransactionScope

Background: I have an ASP.NET MVC application that wraps controller actions in a TransactionScope using an Action Filter.

再往下游(在我的基础架构层);我想开辟一个新的ADO.NET连接(同一个分贝我的外TransactionScope的,如果这是相应和),并有其参与自己的事务 - 而不局限于当前的TransactionScope开始在控制器级别;我怎么去这样做?

Further downstream (in my infrastructure layer); I'd like to open up a new ADO.NET connection (to the same db as my outer TransactionScope, if that is relevent) and have it participate in its own transaction - without being tied to the current TransactionScope started at the controller level; how do I go about doing this?

推荐答案

您传递的 <$ C C> TransactionScopeOption.RequiresNew $

You pass in TransactionScopeOption.RequiresNew:

TransactionOptions to = new TransactionOptions;
to.IsolationLevel = <desiredIsolationLevel>;
using (TransactionScope scope = new TransactionScope(
   TransactionScopeOption.RequiresNew, to))
{
  ... do work here
  scope.Complete ();
}

要当心虽然有不足该大桥龙。特别是易死锁与自己是否涵盖范围已挂起从自己的事务范围内提交的写操作,并尝试触摸非常相同的实体内独立事务(新作用域)。

Be carefull though, there be dragons under that bridge. Specifically is easy to deadlock with yourself if the encompassing scope has pending uncommitted writes from its own transaction scope and you attempt to touch the very same entities in the inner standalone transaction (the new scope).

这篇关于一个TransactionScope内隔离ADO.NET连接和事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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