【问题标题】:TransactionScope and Error: ORA-02049TransactionScope 和错误:ORA-02049
【发布时间】:2010-12-10 05:54:05
【问题描述】:

我有以下例程:

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: 超时: 分布式事务等待锁定

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

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

提前致谢。

【问题讨论】:

    标签: vb.net oracle oracle11g ora-02049


    【解决方案1】:

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

    这里只是头脑风暴,但如果是dbValueLookup.Count = 0,那么您将调用addData(听起来像是INSERT?),但您不会调用scope.Complete() 来提交您的事务。

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

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

    【讨论】:

      猜你喜欢
      • 2011-01-31
      • 2016-02-04
      • 2015-08-24
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 2016-10-22
      • 2020-03-10
      • 2016-07-07
      相关资源
      最近更新 更多