Reputation: 2123
A problem i have faced during testing of my application which is
from two different browser i have open my application and open same page from i am doing some operation.
Then request for update data at same time from both browser. and data from both browser are save in database which is wrong.
I have done some code for prevent this issue like first check that values are exist in database or not. but this kind of validation can't prevent of concurrency saving of data.
Please help me. I need to resolve this issue.
Thanks in adavance
Upvotes: 0
Views: 2021
Reputation: 303
You can prevent concurrency error saving data by using Optimistic or Pessimistic locking
Optimistic Locking
There are 3 primary ways by which we can implement optimistic locking in .NET:-
Datasets
: - Dataset by default implement optimistic locking. They
do a check of old values and new values before updating.
Timestamp Data type
: - Create a timestamp data type in your table
and while updating check if old timestamp is equal to new timestamp.
Check old and new value
: - Fetch the values, do the changes and
while doing the final updates check if the old value and current
values in database are equal. If they are not equal then rollback or
else commits the values
Pessimistic Locking
For more information, check out: http://www.codeproject.com/Articles/114262/ways-of-doing-locking-in-NET-Pessimistic-and-opt
Upvotes: 1