【问题标题】:catch locked oracle sql record c#捕获锁定的oracle sql记录c#
【发布时间】:2015-08-28 09:08:39
【问题描述】:

我尝试通过 c# 更新记录。它工作正常,但是如果其他人编辑了相同的记录并且没有提交或回滚它(因此事务仍然打开),程序将冻结,直到它被提交或回滚。这不是问题,但我不希望程序冻结。它应该打印一个错误或其他东西。

有什么线索可以抓住它吗?

【问题讨论】:

    标签: c# sql oracle record locked


    【解决方案1】:

    在你的情况下,你必须

    1. 尝试锁定记录以进行更新(独占锁定)
    2. 如果成功,更新它们在相同的事务中

    因此,您应该执行类似的操作,而不仅仅是 update

      select 1
        from MyTable
       where id = :prm_Id   -- the same condition as in the update part
         for update nowait; -- throw exception if the record is locked; 
                            -- "skip locked" is an alternative Oracle 11g behaviour
    
      update MyTable
         set myField = :prm_myField
       where id = :prm_Id;
    
      commit; -- or continue the transaction
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      相关资源
      最近更新 更多