)致力于即使System.Transactions.TransactionScope.Commit(数据不叫不叫、致力于、数据、System

由网友(ゞ 仅有的敷衍)分享简介:在什么情况下可以code包裹在一个 System.Transactions.TransactionScope 还是犯,即使一个异常被抛出和最外层范围从来没有犯叫什么名字? Under what circumstances can code wrapped in a System.Transactions.Transa...

在什么情况下可以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?

推荐答案

答案竟然是因为我在在的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.

阅读全文

相关推荐

最新文章