Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mmarino
Starting Member
2 Posts |
Posted - 2002-02-06 : 10:28:25
|
| I've bee reading how SQL handles locking, but I'm still pretty confused. I'm writing a multi-user application in VB6. I pull a record from a table using ADO, and display it. Then the user has the option to make changes to this record (they have to press a button to enter this mode), so at this point I'd like to lock the record (one row) so no one can make changes to it, but I would like to allow other users to read it. Now, if the second user tries to click on the Edit button I want to tell them that the record is locked. Is there a simple way to do this? Logically it seems very straight forward, but I can't find the implementation anywhere.Thanks a bunch,Monica |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-02-06 : 10:50:42
|
| Check this Link. there was a similar issue ,thought it will help youhttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=11843--------------------------------------------------------------Dont Tell God how big your Problem is , Tell the Problem how Big your God isEdited by - Nazim on 02/06/2002 10:53:06 |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-02-06 : 11:04:53
|
| I wouldn't try to use sql server locking for this.Usual way is to include a timestamp on the record. On the update check the timestamp - if it has changed then someone else has updated the record and you return an error to the user.If you want to lock the record for update (remember that if a user gets the record then goes away locking his machine then no one will be able to update that record until someone turns his machine off).Create a =nother tableRecordLock(spid, logontime, recordID)logontime comes from master..sysprocesses and is needed to make sure that the user has not killed the connection and someone else has got the spid.To get the record add @@spid, logontime, recordID to this table.To update check that spid/logontime exist for this record.To get the record for update check that the recorID does not exist in the table for a current spid/logontime.Put the users spid/logontime/recordID in the table.These should be either done in one statement or the table locked for the check to ensure that 2 people don't get the same record.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|