How to lock Record for Update & Delete

  • Hi Friends,

    I'm totally new to Multiuser application development. The real problem I'm facing is about locking a record while more than one user need to access it.

    I'm using VB with SQLServer. In VB I use ADODB recordset to access data from SQLServer.How can I find weather a record had been deleted by one user after it fetch for modification by another user. Since my users some take long time to submit their updates, I dont want to keep the record locked. Can any one tell me about the best possible way or any other related resource in net.

    Thanks

    Manoj

    P.B. No 14337

    Doha - Qatar

    Ph: 4435361

    web:www.fccqatar.com


    P.B. No 14337
    Doha - Qatar
    Ph: 4435361
    web:www.fccqatar.com

  • Your best bet is to lock the record but this will cause a performance hit. You only other options are 1, have a timer recheck the data peridoically to verify and the moment changes or dissappears pop a message record has changed or is no longer available and decide how to handle especially if they have made changes to a field. Another way would be to wait until the changes are submitted by the user and if you get the error record does not exist just pop them the message. Or another possibility is create a checkout method were you track who has called the record and show this to the others so they can be aware of this and maybe find out why before submitting their changes.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • With ADO you should get a meaningful error message back if the record has been deleted. If you do an update via stored proc you'll need to return status, either via an output parameter or the return code - the update will not "fail" because the record is gone, it just won't update anything!

    You also have to deal with record being changed if you're not locking (optimistic locking). If you look at ADO it supports a property called 'update criteria' that you can set to one of a few values; key, all columns, updated columns, timestamp, that tells ADO how to know whether its ok to update the record.

    Im not a fan of application implemented locking, but it does have its place. Pessimistic locking certainly has its place, but the implications for scalability restrict it's use.

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply