2009-10-26 5 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 

모두 우리의 생산에 대해이 실행 산발적으로 오라클 11g 데이터베이스를 테스트 (또는 패턴이있는 경우, 나는 아직 그것을 발견하지 않았습니다 ORA-02049 : timeout : 분산 트랜잭션이 대기 중입니다.

이것은 테스트 데이터베이스에 대해 실행되는 유일한 프로세스이므로 다른 사용자가 잠금을 놓고 경쟁하는 데 문제가 없어야합니다.

어떤 아이디어가이 오류의 원인 일 수 있습니까?

미리 감사드립니다.

답변

0

그래서 행 잠금을 위해 두 개의 트랜잭션을 경쟁해야하는 것처럼 들립니다.

그냥 여기 브레인 스토밍,하지만 dbValueLookup.Count = 0 경우에, 당신은 addData를 호출합니다 (그것이 INSERT를하는 것처럼 들린다?), 그러나 당신은 당신의 트랜잭션을 커밋 scope.Complete()를 호출하지 않습니다.

End Using이 항상 트랜잭션을 커밋할지 여부는 확실하지 않습니다.

루프의 반복마다 실제로 TransactionScope을 만들어야합니까? 왜 하나의 트랜잭션을 만들지 마시고 모든 업데이트/삽입을 한 번 하시겠습니까?