Click to See Complete Forum and Search --> : Locking a record in an MS-SQL Database


on1ami
June 25th, 2002, 08:48 AM
Hello to All,

I’m writing an application in C# accessing an Microsoft SQL Database Server for consulting, creating and updating . The Database is accessed via the internet , the local network or even via telephone. Because the risk of losing connection I stay as short as possible connected to the database and use only INSERT, UPDATE or SELECT statements to perform my duty.
If the user selects a record, I get it with a SELECT. When the user has changed data I first read the old record, compare it to see if an other user did not change the record and then I write it to the database using an UPDATE.
I was just wondering if there is a way to lock a record using an SQL instruction or whatever from the moment the user starts to make changes, close the connection. When all changes are made, open the connection, write the changes and then free up the lock before closing the connection at new. This in combination with triggers on the database who frees the locks when a user is not updating the record within a predefined time.

If anyone has experience working in that way I would be thankful to hear how you solved the problem.

Greetings,
Jean Paul.