all groups > sql server msde > december 2005 >
You're in the

sql server msde

group:

Locking a record.


Locking a record. William GS
12/13/2005 4:58:02 AM
sql server msde:
Hello, how can I lock a record? it must be modified only for one user at the
same time.

Thansk in advance.
Re: Locking a record. William GS
12/13/2005 7:00:02 AM
Andrea, thank you for the help; actually, I am using ADO.
William GS


[quoted text, click to view]
Re: Locking a record. Andrea Montanari
12/13/2005 3:35:11 PM
hi William,
[quoted text, click to view]

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 Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.16.0 - DbaMgr ver 0.61.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

AddThis Social Bookmark Button