What is the difference between optimistic locking and pessimistic locking?
Locking is a concept implemented in order to guard records that will be accessed by multiple users so that concurrency errors can be avoided. It prevents access through some technique and protects a record when a user is doing an update.
Optimistic locking is better to use when the chances of an update conflict is low. This is usually the scene when the routine activity is happening by adding a record. Pessimistic locking is used when the chances of a conflict is high.
Pessimistic locking guesses contention for the same record thereby prevents users from selecting a record for editing whenever the other user has done it beforehand. This is usually carried out by banking upon the database itself. Most relational databases utilize this method. However, each database may use a different approach for the way locking is done. For example, the SQL Server 2000 locks single rows, whereas others may lock the entire page or table containing the record to be changed. One of the drawbacks is that this type of locking demands that you remain connected to the database all the time.
Optimistic locking facilitates multiple users to access the same record for edits, counting on minimal conflicts over data. The locking occurs after the user tries to save changes on someone else's actions. The program logic checks to see if the record has been changed since the time you opened it. If it has changed, then an error is thrown and the update is rolled back. On the other hand, if no changes are detected, then the record is saved.
ASP.NET Expression Symbols
Web Service in ASP.NET
Pass data to Web Control
Zipping a folder in ASP.NET
Check user online or offline
Display Dynamic Tooltips
Dynamic Server Side Tables
Capture Gridview Row Index
Improve ASP.NET Performance
Refresh page in another page
Step into DLL Source Code
Insert Non-Ascii Characters in a Database
Contract in WCF
Asp.net triggering a Postback
~ Character in ASP.NET
Web Application Project VS. Website Project
Optimistic Locking VS. Pessimistic Locking
System.Net.Mail VS. System.Web.Mail
Breakpoints in debugging
More Interview Questions...