Hi,
I want to know that , Is locking is the good practice on a database part and if yes then how can i put the locks on the database ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Datta KharadPosted Jan 31, 2012, 1:02 AM
Yes, because of database Deadlocks occur when 2 or more transactions hold dependent locks and neither can continue until the other releases. Below is a simple illustration of a deadlock.
Time User 1 Actions User 2 Actions
1 Starts Transaction
2 Starts Transaction
3 Updates row 2 in table A
4 Updates row 10 in table B
5 Attempts to update row 10 in table B
U1 Is Blocked by U2
6 Attempts to update row 2 in table A
U1 Is Blocked by U2U2 Is Blocked by U1
DEADLOCK!!!
This example is the simplest type. Deadlocks can be much more complicated, involving different types of locks, and involving more than 2 sessions.
The good news is that the DBMS will recognize these situations and resolve them. The DBMS will choose one "victim" and roll back their transaction. The DBMS tends to choose the "victim" by determining which transaction will be easiest to roll back. However, unless the application is designed to react to deadlock errors and retry, there will be a negative end-user impact.
Deadlocks generally lead to intermittent errors. They are almost always caused by application logic problems. These generally occur when the application does not access data in a consistent sequence. They are also very timing and data dependent, which can make them very hard to reproduce.
//For more detail refer below article:-
http://www.c-sharpcorner.com/uploadfile/shivprasadk/6-ways-of-doing-locking-in-net-pessimistic-and-optimistic/