2009-10-26 44 views
4

我有以下程序:的TransactionScope和錯誤:ORA-02049

For j = 1 To NumItems 
    dbValueLookup.Load(j) 
    Using scope As New TransactionScope() 
     For i = firstIndex To lastIndex 

      'dbValueLookup is basically just a Dictionary of items already in the DB 
      If dbValueLookup.ContainsKey(i) Then 
       'updateData is a subroutine that updates this row with new data 
       updateData(j,i) 
       rowsUpdated = rowsUpdated + 1 
       dbValueLookup.Remove(i) 
      Else 
       'updateData is a subroutine that adds a new row to DB 
       addData(j,i) 
       rowsAdded = rowsAdded + 1 
      End If 
     Next 

     If dbValueLookup.Count = 0 Then 
      'This commits the transaction - records will be updated when End Using is reached 
      scope.Complete() 
      If rowsAdded + rowsUpdated > 0 Then 
       ShowMessage("Records Updated: " + rowsUpdated.ToString() + " Records Added: " + rowsAdded.ToString()) 
      End If 

     Else 
      'We are left with data from the database that was not updated. This is a problem, so we don't "Complete" the scope. 
      'This will result in a rollback. 
      ShowWarningMessage("Incomplete Data for " + i.ToString()) 
     End If 
    End Using 
Next 

運行這對陣雙方我們的生產和零星測試的Oracle 11g數據庫(或者,如果是有規律的,我還沒有找到它)生成的Oracle錯誤: ORA-02049:超時:分佈式事務正在等待鎖定

由於這是針對測試數據庫運行的唯一進程,所以不應存在不同用戶競爭鎖定的問題。

任何想法可能會導致此錯誤?

在此先感謝。

回答

0

所以這聽起來像你必須有兩個交易競爭行鎖。

只是集思廣益這裏,但如果dbValueLookup.Count = 0,那麼你將調用addData(這聽起來像它的INSERT?),但你不會打電話scope.Complete()提交您的交易。

我不確定End Using是否會一直提交事務。

您是否真的需要在循環的每次迭代中創建TransactionScope?爲什麼不創建一個事務,做所有更新/插入,然後提交一次?