views:

51

answers:

1

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?

Thank you

+2  A: 

You can't lock a row like that using DB engine locks.

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.

gbn
+1 definitely - don't even get into that "locking by yourself" mess - it's just not worth the trouble...
marc_s
Thanks, I will go with timestamp method.
David
+1, I do this, when you load the data for the page get the complete datetime of the last change. when you go to save the data include `AND LastChangeDate=.......` on the UPDATE, if rowcount=0 then I issue an error message about someone else has already changed that data.
KM