Locking a record.

Microsoft SQL Server

Hello, how can I lock a record? it must be modified only for one user at the
same time.

Thansk in advance.
William GS
hi William,
probably it depends on the object model you use to access your data...
ADO supports a pessimistic lock when you open a server side connection
(.CursorLocation = adUseServer) and set the .LockType = adLockPessimistc
property of a recordset object.. as no .Edit property is available in ADO
model, the record itself gets locked when you access it for midification, ie
when you set objRS.Fields(0).Value = objRS.Fields(0).Value which actually
does nothing but trying (and an exception is raised if it fails) to lock the
row by modifying it...
this does not work with ADO.Net as no pessimistic lock is available so you
have to rely on SELECT lock hints,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_7a_1hf7.asp ,
but it is quiet difficult to hold such locks for a coffee break duration (an
ipotetic employee's break :D) ...
you should try to modify your design in order to use the "new" standards to
not to lock a resource until needed (UPDATE/DELETE/INSERT actual moment),
and this is quiet transparent to you as it is well performed by SQL Server
it self..
Andrea, thank you for the help; actually, I am using ADO.
William GS