励志照亮人生,创业改变命运!

SqlConnection.BeginTransaction()方法

上一篇 / 下一篇  2008-05-16 11:50:38 / 个人分类:ASP.NET

此命令映射到 BEGIN TRANSACTION 的 SQL Server 实现。

测试代码如下:

                sqlcommand = clsDbConnect.S_sqlConnection.CreateCommand();ITPUB个人空间(YQ`6s"Hm$?u
                sqlcommand.Connection = clsDbConnect.S_sqlConnection;ITPUB个人空间Ol_L-n-zT2z&S
                sqlcommand.Transaction = clsDbConnect.BeginTransaction();ITPUB个人空间JeE@)g8z3[G
                sqlcommand.CommandText = sqlstr;ITPUB个人空间Q | V'bA"X'mi"e0`
                sqlcommand.ExecuteNonQuery();ITPUB个人空间8h^5ub sBS
                sqlcommand.CommandText = sqlstr;ITPUB个人空间2L5dsWO/r*p&I-_;E
                sqlcommand.ExecuteNonQuery();
A,q$k'Q9@Vep~0                clsDbConnect.EndTransaction(true);

结论:支持事务并发操作。

微软代码:

            command.CommandText =ITPUB个人空间,l"HW hI&]2Q)?
               "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
2{Dd-oL7v"m:h0            command.ExecuteNonQuery();ITPUB个人空间4`{1j%|9A&A
            command.CommandText =
&fk~-K7z8_K"}U0               "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
'bj} t9YU$U+y0            command.ExecuteNonQuery();ITPUB个人空间 qP z)u,U0W3WK(Q
           // Attempt to commit the transaction.ITPUB个人空间 \9VW4p9bKCHb VF
            transaction.Commit();
v lq\-}Q0            Console.WriteLine("Both records are written to database.");

结论:微软代码本人未测试,但他的意思是不支持事务并发操作。并会抛出InvalidOperationException异常。


fu1Ri8I:QEf!i0 


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-07-24  
  12345
6789101112
13141516171819
20212223242526
2728293031  

数据统计

  • 访问量: 380
  • 日志数: 13
  • 建立时间: 2008-03-24
  • 更新时间: 2008-06-26

RSS订阅

Open Toolbar