Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I've an ASP.NET application. Two users logged in simultaneously and in a Grid page both users choose same record. User1 modifies some data and click submit button. User2 modifies data and click submit button. At this time I would like to show a Pop-up message saying that Another User (ie User1) modified that data. Upon clicking Ok button I would like to rollback the User2's transaction. How to achieve this. Please guide me.

It would be great if I get any sample application or code. Thanks.
Posted

1 solution

Lets say your record is stored in Database with a version

RECORD ID VERSION
1000001 2

If the user 1 and 2 picks up same record 1000001,you fetch the record details from the database along with the version number in this case '2'.

So on submitting the record you check whether the version the user submitting is exactly same as what it is in database by doing a UPDATE WITH VERSION in WHERE CONDITION. For the first user whose version number is same as the database version, the update will go through and will return 1 as number of records updated. For the second user number of records updated will be 0.By the result of updated count you can show the error message.

SAMPLE QUERY:
UPDATE RECORD TABLE SET RECORDDETAIL='TEST',VERSION=VERSION+1 WHERE RECORD_ID=1000001 and VERSION=2

This is manual implementation. If you use nHibernate it will take of locking and concurrency.
 
Share this answer
 
v2

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