View Single Post

   
  #4 (permalink)  
Old 02-29-2008, 06:52 AM
Erland Sommarskog
 
Posts: n/a
Default Re: Determine which user has locked a record

David C. Barber (david@NOSPAMdbarber.com) writes:
> I'm trying to determine which user has locked a given record from VB6.
>
> I know I can use sp_lock and sp_who, and match up the data to determine
> which users have locked records in my database, however I haven't seen a
> way to match the specific user to the specific record. What am I
> missing here?


To echo what Dan said: you are barking up the wrong tree. The locking
mechanism in SQL Server is there to ensure atomicity of transactions.
If you have business requirements that makes it necessary one user to
reserve a record, and another user to see who has it reserved, you should
roll your own.

To this end, you probably need a few columns to the table with username,
time for the reservation, and possibly some more information. One thing that
you need to consider is that a reservation may become stale. That is, the
user who makes the reservation never completes the operation.

You should in no way rely on SQL Server locking mechanism, and you should
absolutely not keep locks while waiting for user input. This can cause
your application to grind to a standstill.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Reply With Quote