C#关于事务的操作

 

            TransactionOptions tOption = new TransactionOptions();
            tOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, tOption))
            {               
             xxx();
             xxx();
               ts.Complete();
            }                

这里两个sql执行时,其中的一个sql执行错误,另一个就会回滚。

 

//注意,事务最好不要嵌套。

//滚回只限于数据库,当外面回滚的时候,里面的操作也会回滚

//如果必须使用事务嵌套,最好使用存储过程。

//存储过程:http://www.cnblogs.com/yangpei/archive/2010/10/07/1894408.html

posted on 2017-08-18 09:41  TheHeist  阅读(348)  评论(0编辑  收藏  举报