Page 1 of 1

Record locking

Posted: Sun 25 Dec 2005 17:32
by Sawlmgsj
I have two users editing the same record at the same time. One saves the record and then the other saves the record a few seconds later. Is there a way to indicate to the second user that updates have just been done by the first user.

This was fairly automatic with my program using Ms Access, but I do not know how to do it with SQL and SDAC. (I have experimented with the isolation level but cannot see how to make this work.)

Thanks,
Steve.

Posted: Mon 26 Dec 2005 10:51
by Ikar
SQL Server doesn't provide such functionality.

Posted: Sat 31 Dec 2005 19:18
by Abadia
Do this:
1 - StartTransaction
2 - set lock time out to 0
3 - select the register with lock hint UPDLOCK like this:
SELECT au_lname FROM authors WITH (UPDLOCK)
if no error happens, then the register is locked
4 - select the register with all fields and join as you need.

ps: the lock is released only end of transaction (commit or rollback)
:D

Posted: Mon 02 Jan 2006 16:04
by tinof
Hi,

find the post of abadia very interesting, please allow me a question :
I have learned (in theory and praxis too (Pervasive.SQL Database) ) "Never let a transaction active while user input! " - the user starts editing, goes away (because it's breakfast :) ) and the records remain locked. I have seen very 'blocked' databases programming this way. As i said - using Pervasive.SQL. How looks this with SQL - Server ? What exactly does the lock timeout ?
Thanks for avice

Tino.

Posted: Thu 05 Jan 2006 12:28
by Abadia
Hi,

The lock time out on SQLServer is only amount of time wait for a locked record. When it's 0, means: don't wait.

About trasactions:
There are two logics. Optimistic and pessimistic. In your instance damand for pessimistic logic. In case of need (because it's breakfast :lol:) you can implement a timer idle function for auto-rollback transaction and free locked register.

Abadia.