User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 361,897 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,355 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 8154 | Replies: 2
Reply
Join Date: May 2005
Posts: 15
Reputation: ramareddy_dotne is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ramareddy_dotne ramareddy_dotne is offline Offline
Newbie Poster

optimistic and pessimistic locking

  #1  
Oct 8th, 2005
what is the difference between optimistic locking and pessimistic locking in ado.net
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Iowa *sob*
Posts: 36
Reputation: npasma is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: optimistic and pessimistic locking

  #2  
Oct 10th, 2005
Optimistic vs. Pessimistic Locking

OK Eddy, here goes:

Locking is a method used to protect records that will be accessed by multiple users so that concurrency errors do not occur (when multiple users change records near simultaneously resulting in inconsistencies).
"Locking" refers to preventing access in some way to the file in order to protect it while a user is making an update.

Optimistic locking is better to use when the likelihood of a update conflict is low. This is usually the case when the normal action is adding a record, like in an order entry system. Pessimistic locking is used when the likelihood of such a conflict is high.

Pessimistic locking anticipates contention for the same record, preventing users from selecting a record for editing when another user has already done so. This is often done by relying on the database itself. Most relational databases use this method, only each may use a different standard for the "granularity" considered when making a lock. As an example, SQL Server 2000 locks single rows, while others may lock the entire page or table containing the record to be changed. A drawback is that this type of locking requires that you remain connected to the database the whole time, which can be a bit much to ask. Also, this type of locking can back up on users waiting to access a given record.

Optimistic locking allows multiple users to access the same record for edits, counting on minimal conflicts over data. The "locking" happens after the user tries to save changes on top of someone else's changes. The program logic checks to see if the record has been changed since you opened it. If it has, an error is thrown and the update is rolled back. If no changes are detected, the record is saved as planned.

As you can tell, there are advantages and disadvantages to both. :-|
So the fun part is deciding which approach best suits your needs.

Hope this helps! Good luck!
Reply With Quote  
Join Date: Jun 2005
Location: Iowa *sob*
Posts: 36
Reputation: npasma is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: optimistic and pessimistic locking

  #3  
Oct 10th, 2005
P.S.- If I just gave you an answer to a homework problem, you owe me $20. :evil: :p :cheesy:
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 8:36 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC