)致力于即使System.Transactions.TransactionScope.Commit(数据不叫 [英] Data committed even though System.Transactions.TransactionScope.Commit() not called

查看:245
本文介绍了)致力于即使System.Transactions.TransactionScope.Commit(数据不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下可以code包裹在一个 System.Transactions.TransactionScope 还是犯,即使一个异常被抛出和最外层范围从来没有犯叫什么名字?

Under what circumstances can code wrapped in a System.Transactions.TransactionScope still commit, even though an exception was thrown and the outermost scope never had commit called?

有包裹在使用(VAR TX =新的TransactionScope())顶级的方法,并调用也使用方法的TransactionScope 以相同的方式

There is a top-level method wrapped in using (var tx = new TransactionScope()), and that calls methods that also use TransactionScope in the same way.

我使用的是类型化数据集相关的TableAdapter的。难道说在适配器的命令没有争取出于某种原因?做任何你知道有人可能会检查他们是否争取在周围的TransactionScope与否?

I'm using typed datasets with associated tableadapters. Could it be that the commands in the adapter aren't enlisting for some reason? Do any of you know how one might check whether they are enlisting in the ambient TransactionScope or not?

推荐答案

答案竟然是因为我在<创建的TransactionScope 对象 / STRONG >在的SqlConnection 对象。

The answer turned out to be because I was creating the TransactionScope object after the SqlConnection object.

我从这个感动:

using (new ConnectionScope())
using (var transaction = new TransactionScope())
{
    // Do something that modifies data

    transaction.Complete();
}

这样:

using (var transaction = new TransactionScope())
using (new ConnectionScope())
{
    // Do something that modifies data

    transaction.Complete();
}

和现在的作品!

所以,这个故事的寓意是创建的TransactionScope 第一

So the moral of the story is to create your TransactionScope first.

这篇关于)致力于即使System.Transactions.TransactionScope.Commit(数据不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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