ADO.NET 1.1和2.0事務的區別

林堯彬發表於2020-04-04
SqlTransaction trans;

trans = con.BeginTransaction();
cmd.Transaction = trans;
try
{
    cmd.ExecuteNonQuery();
    trans.Commit();
}
catch(Exception e)
{
    trans.Rollback();
}
finally
{
    con.Close();
}
================================
using System.Transactions;
//// <summary>
/// 事務測試方法-- Add by Teracy on 2007-09-09
/// </summary>

void TestTransaction()
{
 TransactionOptions options = new TransactionOptions();
 options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = TransactionManager.DefaultTimeout;

           using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
         {
              //資料操作第一步;
            //資料操作第二步;
           //資料操作第三步;
             scope.Complete();        
           }

  }

轉載於:https://www.cnblogs.com/RobotTech/archive/2007/10/12/922271.html

相關文章