2009-04-28 112 views
1

我正在跨多個系統進行數據庫事務(插入記錄)。所以,我決定在.net中使用System.Transaction命名空間。我在兩個系統上配置了MSDTC(但我不知道我是否正確配置)。我的事務有兩個插入查詢一個將在本地系統執行。另一個將在本地網絡中的某個其他系統上執行。 第一次插入查詢成功,但第二次提出錯誤,如: Message =「該事務已被隱式或顯式提交或中止。」分佈式事務處理協調器

請幫助在這種情況下結束。


這裏是我的代碼

using (TransactionScope txSc = new TransactionScope()) 
    { 
     //vrm = new VolatileRM(); 
     //vrm.SetMemberValue(3); 
     try 
     { 
      using (SqlConnection cn = new SqlConnection(connStr1)) 
      { 
       SqlCommand cmd = cn.CreateCommand(); 
       cmd.CommandText = "Insert into empdetail Values ('YYY')"; 
       cn.Open(); 
       cmd.ExecuteNonQuery(); 
       cn.Close(); 
      } 
      using (SqlConnection cn = new SqlConnection(connStr)) 
      { 
       SqlCommand cmd = cn.CreateCommand(); 
       cmd.CommandText = "Insert into stu Values ('23','senthil')"; 
       cn.Open(); 
       cmd.ExecuteNonQuery(); 
       cn.Close(); 
      }      
      txSc.Complete(); 
     } 
     catch (Exception e) 
     { 
      txSc.Dispose(); 
     } 

    } 
+0

你可以編輯我包括包含整個事務的代碼。 – Fung 2009-04-28 06:17:06

回答

2

首先檢查DTC實際運行(在本地和遠程系統),然後嘗試都DTC的身份驗證設置爲「無名氏」,看它是否是一個權限問題。

此外,請檢查遠程和本地計算機上的防火牆設置。

看看這個常見問題:Distributed Transaction Coordinator(MSDTC) and Transaction FAQ

Configuring MS DTC Services

與此相關的SO問題:HRESULT: 0x8004D00E using TransactionScope - C#

+0

謝謝,我會這樣做 – Partha 2009-04-28 06:38:40