TransactionScope

 

using System.Transactions;



            using (TransactionScope scope =
                new TransactionScope(TransactionScopeOption.Required,
                   new TransactionOptions
                   {
                       IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
                       Timeout = new TimeSpan(0, 0, 120)
                   })
               )
            {
              try

              {

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql("delete from  [user] where id=5;");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789',123);");//错误方法

                  scope.Complete();

              }

              catch (Exception ex)

              {

 

                  Console.WriteLine(ex);

              }

            }

 

posted @ 2023-08-25 14:32  山顶洞外人  阅读(8)  评论(0编辑  收藏  举报