事務測試

在不改變現有代碼的基礎上增加事務

缺點 消耗系統資源比較大,響應比較慢.

 

static public void testTran()
  {
   ServiceConfig sc = new ServiceConfig();
   sc.Transaction = TransactionOption.Required;
   sc.TrackingEnabled = true;
   ServiceDomain.Enter(sc);
   try
   {     
    Insert("1"); 
    Insert("a"); 
    ContextUtil.SetComplete();
   }
   catch (System.Exception except)
   {
    HttpContext.Current.Response.Write(except.ToString());
    ContextUtil.SetAbort();
    
   }
   finally
   {
    ServiceDomain.Leave();
   }
  
  }
  


 static public void Insert(string val)
  {
   string sql="insert into test1 (number) values ('"+ val  +"') ";

   DBClass.SqlHelper.ExecuteDataset(DBClass.SqlHelper.CONNSTR,CommandType.Text,sql);
  
  } 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章