|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:57 PM
Points: 20,
Visits: 36
|
|
Question1: How can a user, say User1, be able to lock a row, say Row1, and any dependent rows, say Row11, Row12, until changes are made to the specific row by User1 Question2: If another user, say User2, wants to access Row1 or Row11, Row12, when these rows are locked by User1, is there a way to let User1 know about it and in the worst case force the unlock, or have some kind of timeout whne User1 is inactive Thanks, John
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:57 PM
Points: 20,
Visits: 36
|
|
Thanks for your reply and suggestion article. I am doing some reading in the mean time.
One of the problems which I am trying to solve is once a user accesses (checks out) a secific record in a table, I would like all subsequent accesses to this specific record by other users to result in a message saying that the record has ben checked out by UserA and not allow changes if UserA does not release the record.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:18 PM
Points: 37,744,
Visits: 30,025
|
|
For that you'd need to manually reimplement SQL's locking mechanism, probably with a locking table, manual checks, manual notifications in all code that you have. You then need to consider all the complications of rows getting locked but never unlocked, etc. It's a hell of a lot of work and very easy to get wrong.
iirc there's a chapter on implementing something like this in Expert SQL Server 2005 Development (yes, the 2005 version)
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:57 PM
Points: 20,
Visits: 36
|
|
Many thanks for your reply Gail,
I appreciate the fact that it would be easy to mess up. If a user needs to work on a specific record for a few minutes and during this time we want to disallow any modifications to the record can we introduce an extra boolean field in the table which would indicate whether the record is checked out or not?
John
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:18 PM
Points: 37,744,
Visits: 30,025
|
|
john 60195 (12/31/2012) I appreciate the fact that it would be easy to mess up. If a user needs to work on a specific record for a few minutes and during this time we want to disallow any modifications to the record can we introduce an extra boolean field in the table which would indicate whether the record is checked out or not?
You can.
Every single piece of code that you have must then honour and check that (and there's no way SQL can enforce that, you will have to in your code). You need to take great care that two connections can't both think they locked the record (very easy to do if you haven't got the isolation levels, locks and transactions exactly right in your locking code). You need some process/method to unlock rows that have somehow remained locked even though the user is done (many, many possible causes) while not unlocking rows that the users are just taking their time over.
You're looking at massive amounts of development here, huge testing requirements and very likely a lot of related bugs.
Is it really, absolutely necessary to reimplement the database locking methodology yourself? Is it worth the time and effort? Grab that book I mentioned and have a read through the chapter on this. It's an entire chapter devoted to the myriad ways of getting this kind of process wrong.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
john 60195 (12/31/2012) One of the problems which I am trying to solve is once a user accesses (checks out) a secific record in a table, I would like all subsequent accesses to this specific record by other users to result in a message saying that the record has ben checked out by UserA and not allow changes if UserA does not release the record. Technically this is possible (as gail commented above ) but not recommended. Can you share the actual requirement(businees requirement) so that we might help you.
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:57 PM
Points: 20,
Visits: 36
|
|
Many thanks for your input to both of you.
I have developed a Dental Practice Management Software package (www.VisualDentist.com) using Access and Jet. While this setup is adequate for a small to medium Dental Practice it is not for a large one, hence the interest to use SQL Server.
The problem which I would like to address deals with accessing the dental record of a patient. This includes information relating to the graphical representation, work details, personal details, financial details etc. Assume the Patient records are in tblPatient (let's forget for the time being any one-to-many relationships with other tables). If a user accesses a record (a patient) in tblPatient, the user will have in front of him a graphical picture of teeth. If the user keeps this picture on his screen for some time (say 5 minutes) and subsequently makes a change, I would like any other users accessing this record during those 5 minutes, to be alerted that the record is under modification and maybe prevented from making any changes until the original user finishes with this patient record.
Does this help?
Regards, John
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 3:18 PM
Points: 37,744,
Visits: 30,025
|
|
Everything I've said stands. You are looking at a huge amount of development and testing and probably a tonne of bugs and irritations. This isn't a 5 minute job.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:57 PM
Points: 20,
Visits: 36
|
|
Gail, have taken your advice seriously. I will see whether the functionality can be modified to avoid the headaches. Thanks, John
|
|
|
|