vb.net - TransactionScope 和错误 : ORA-02049

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

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

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

提前致谢。

最佳答案

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

这里只是头脑 Storm ,但如果 dbValueLookup.Count = 0 ,然后您将调用addData (听起来像是 INSERT ?),但你不会调用 scope.Complete()提交您的交易。

我不确定 End Using将始终提交或不提交事务。

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

关于vb.net - TransactionScope 和错误 : ORA-02049,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1626674/

相关文章:

使用预定义值列表作为 SQL 表的 SQL 语句

oracle - 有没有一个工具可以跟踪Oracle上执行的SQL

sql - Not a Group by expression 错误 [连接表]

vb.net - LINQ 中的 Where 子句与 Vb 中的 IN 运算符

vb.net - linq 结合 2 个查询

vb.net - 从 vb.net 中的一串数字中提取特定数字

java - 如何从数据源检查登录名和密码?

mysql - 交叉应用对于较大的数据库不利,还是替代方案性能更好?

sql - SQL Server 中具有多列的“In”子句

oracle - PIVOT 的替代方法 - IN 支持子查询