>>>Hello,
>>>
>>>In our VFP applications, when working with DBF tables, we sometimes used RLOCK() to lock a certain record in order to check the state of things, like for example if a user is logged in, we lock the record of the user in a session table, and then can check which records are locked, knowing which users are logged in. (When the user logs out, or if they lost connection with the server or the program crashes, the lock would eventually get released).
>>>
>>>What is the best way to simulate this functionality in SQL Server?
>>>
>>>Thanks in advance!
>>
>>See
Re: Issue explicit lock for testing Thread #
1347107 Message #
1361095>
>Thanks, but can I issue the Begin Transaction etc in one SQLEXEC() statement? Or do I need to run successive SQL statements and use a separate connection handle of the database?
I was actually thinking you need to simulate lock for testing. SQL Server makes locks itself, so you don't really need to apply locks yourself although you can add them with hints per each statement. Also, if you need to perform an atomic operation (say, insert into 1 table and update another and make sure both happened) you place them into BEGIN TRANSACTION .. COMMIT TRANSACTION blocks. Of course, all commands need to use the same connection and preferrably be sent as one batch.
And after re-reading your question once more, I believe you need to utilize system stored procedure - sp_GetAppLock
http://msdn.microsoft.com/en-us/library/ms189749.aspx
If it's not broken, fix it until it is.
My Blog