事务范围内隔离的 ADO.NET 连接和事务
背景:我有一个 ASP.NET MVC 应用程序,它使用操作筛选器将控制器操作包装在 TransactionScope 中。
更下游(在我的基础设施层);我想打开一个新的 ADO.NET 连接(与我的外部 TransactionScope 相同的数据库,如果相关的话)并让它参与自己的事务 - 而不与在控制器级别启动的当前 TransactionScope 绑定;我该怎么做呢?
Background: I have an ASP.NET MVC application that wraps controller actions in a TransactionScope using an Action Filter.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您传入
TransactionScopeOption.RequiresNew
:不过要小心,桥下有龙。具体来说,如果包含的范围有来自其自己的事务范围的待处理的未提交写入,并且您尝试接触内部独立事务(新范围)中的完全相同的实体,则很容易与自己陷入僵局。
You pass in
TransactionScopeOption.RequiresNew
: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).