【发布时间】:2015-08-28 09:08:39
【问题描述】:
我尝试通过 c# 更新记录。它工作正常,但是如果其他人编辑了相同的记录并且没有提交或回滚它(因此事务仍然打开),程序将冻结,直到它被提交或回滚。这不是问题,但我不希望程序冻结。它应该打印一个错误或其他东西。
有什么线索可以抓住它吗?
【问题讨论】:
标签: c# sql oracle record locked
我尝试通过 c# 更新记录。它工作正常,但是如果其他人编辑了相同的记录并且没有提交或回滚它(因此事务仍然打开),程序将冻结,直到它被提交或回滚。这不是问题,但我不希望程序冻结。它应该打印一个错误或其他东西。
有什么线索可以抓住它吗?
【问题讨论】:
标签: c# sql oracle record locked
在你的情况下,你必须
因此,您应该执行类似的操作,而不仅仅是 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
【讨论】: