Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This question could go to either the DB forum or here.

I'm working on a WPF application. I need to manage multiple users hitting a record at the same time. When the user clicks the 'Edit' button I want to either allow or deny access based on weather or not someone else is using the record.

What's the best way to know if someone's using the record?
Posted

There are essentially 2 approaches.

One is to use Optomistic Locking[^] and the other is a more Pessimistic Lock approach.

The earlier is often done with time stamps. You let the user edit but when they check back in you compare their update time (before they touched the data) to the update time of what is stored. If they are not the same you must reject it (someone just updated).

The pessimistic lock is the idea that you make a table (or something) that tracks when an object is "Checked Out". If it is checked out then no one else can check it out. Often you want to put some rules around check outs like expiration or identity principal.

I would recomend the later, but the Optomistic is easier to build since you just compare some time stamps and reject the entry if it is not correct. The optimistic approach works if you do not have to many end users that touch the same entries.
 
Share this answer
 
v3
Someone once suggested using lock files. The idea is that when the user navigates to a record, if there's a lock file in place and that file is read-only then someone else is editing that record.

If the lock file's not there, then the record is not in use and can be edited.

If the file's there but read-write, then the the app crashed previously, but te row is currently not in use.

When the user moves off the record the lock file is unlocked and deleted.


I'm not sure about this idea. What do you think?
 
Share this answer
 
Comments
[no name] 14-Sep-11 16:10pm    
Not sure what exactly you mean by a lock file. Are you storing the data in a file? If that is the case then when the file is opend (from your application), depending on how you opened it it will become locked. This will cause a difference instance of the application to hang then when opening it.
If you are saying to place an arbitrary file somewhere as the 'lock' keep in mind users can be crafty. If one user figures it out and believes they 'know' what they are doing (maybe they do.. doesn't really matter) that system will eventually fail. e.g. They might show some other user how to "work around" the system, but the other user does not understand what they are doing.
The read only flag is easily manipulated so IMO it is does even qualify as a poor man's lock.
But I do not know the details of your system. On a really small scale that will never (I always regret using that word) upscale it may work... "Maybe" (again, EUs can be quite crafty)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900