TransactionScope和错误:ORA-02049

时间:2009-10-26 18:56:24

标签: vb.net oracle oracle11g 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:超时:等待锁定的分布式事务

由于这是针对测试数据库运行的唯一进程,因此竞争锁定的不同用户不应该有任何问题。

可能导致此错误的任何想法?

提前致谢。

1 个答案:

答案 0 :(得分:0)

所以听起来你必须有两个交易竞争行锁。

只是在这里进行头脑风暴,但是如果dbValueLookup.Count = 0,那么你会打电话给addData(这听起来好像是INSERT?),但是你不会打电话给scope.Complete()来提交你的交易。

我不确定End Using是否会始终提交交易。

你真的需要在循环的每次迭代中创建TransactionScope吗?为什么不创建一个事务,执行所有更新/插入,然后提交一次?