我有一个ASP.Net网页,用户可以在其中选择要编辑的行.我想在该行上使用行锁,并且当用户完成编辑并更新后,另一位用户可以编辑该行,即如何使用行锁,以便只有一个用户可以编辑行?
I have an ASP.Net webpage where the user selects a row for editing. I want to use the row lock on that row and once the user finishes the editing and updates another user can edit that row i.e. How can I use rowlock so that only one user can edit a row?
谢谢
推荐答案您无法使用数据库引擎锁来锁定像这样的行.
You can't lock a row like that using DB engine locks.
大多数其他策略将依靠保持连接打开(例如sp_getapplock),这在Web应用程序中是荒谬的.
Most other strategies would rely on keeping the connection open (such as sp_getapplock) and this is nonsensical in web apps.
即使您在该行上设置了一个标志,如果用户只是简单地在编辑过程中关闭浏览器,会发生什么?
Even if you set a flag on the row, what happens if the user simply closes the browser mid-edit?
我建议使用时间戳/行版本列来检测其他会话中对该行的更改.
I'd suggest using a timestamp/rowversion column to detect changes to the row in other sessions.
更多推荐
SELECT语句上的sql rowlock
发布评论