English 中文(简体)
尽管交易ScopeOption,但封顶的交易滚回。 十二、禁止
原标题:nested Transaction rolls back although TransactionScopeOption.Suppress
  • 时间:2012-01-13 12:18:12
  •  标签:
  • c#
  • .net

我想收回一个称为“镜子”的交易,但所标明范围2的内部交易不应退缩。 但是,他们都 back! 选项 TransactionScopeOption。 2. 禁止工作......

I already enabled DTC and I m using Visual Studio 2010 with .net 4.0 and Microsoft SQl Server 2008. What s wrong here???

using (SqlConnection conn = new SqlConnection(@"Data Source=.DEVELOPER;Initial Catalog=TestDatenbank;Integrated Security=sspi"))
        {

            using (TransactionScope scope = new TransactionScope())
            {

                conn.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "UPDATE Orders SET ID= 111 ";
                cmd.ExecuteNonQuery();


                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
                {

                    SqlCommand cmd1 = new SqlCommand();
                    cmd1.Connection = conn;

                    cmd1.CommandText = "UPDATE Orders SET OrderName= aaa ";
                    cmd1.ExecuteNonQuery();


                    scope2.Complete();
                }


                //scope.Complete();

            }

        }

感谢你们的回答。

最后我!

using (SqlConnection conn = new SqlConnection(@"Data Source=.DEVELOPER;Initial Catalog=TestDatenbank;Integrated Security=sspi"))
        {

            using (TransactionScope scope = new TransactionScope())
            {

                conn.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "UPDATE Orders SET ID= 111 ";
                cmd.ExecuteNonQuery();

                using (SqlConnection conn2 = new SqlConnection(@"Data Source=.DEVELOPER;Initial Catalog=AdventureWorks;Integrated Security=sspi"))
                {
                    using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress))
                    {

                        conn2.Open();

                        SqlCommand cmd1 = new SqlCommand();
                        cmd1.Connection = conn2;

                        cmd1.CommandText = "UPDATE Henrik SET ID= 111 ";
                        cmd1.ExecuteNonQuery();


                        scope2.Complete();
                    }
                }


                //scope.Complete();

            }

        }

我删除线范围2时,有一点奇怪。 完成();取代//范围.Complete();范围。 完成();我希望:

scope will be executed scope2 will roll back

but actually: scope will be executed scope2 will also be executed

是否有任何想法?

最佳回答

我当然不知道,但原因可能是,尽管你确实通过镇压来压制任何野心交易,但你还是利用了与外部范围相同的联系。 因此,这一联系已经参与交易(对外交易),因此所有变化都受到约束。 内部范围没有环境交易的事实可能不会改变。 换言之,压制范围在这方面不会有任何作用。

您可以尝试使用<条码>的新和新的链接操作内部逻辑。

问题回答

设定2个交易范围,分别连接。 在一个层次上,交易范围按每联接水平进行。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签