Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement pessimistic locking in ASP.NET

There is a table called Accounts.The table structure looks like:

 AccountID  AccountName  AccountTotalMoney

   1           Stsven          3000

The account(where AccountID=1) was shared by many users.

So when a user updates the account(locking the account),I would like to prevent others updating the account.

I have visited

6 ways of doing locking in .NET

But I do not understand yet.Sorry for my bad english. Thanks in advance!

like image 626
user441222 Avatar asked Jan 25 '26 20:01

user441222


1 Answers

You can use TransactionScope to implement pessimistic locking (change isolation level)

I think this post can help: Setting the IsolationLevel using the System.Transactions TransactionScope.

Be aware "pessimistic locking" mentioned in the link you posted is different concept of "pessimistic concurrency". Make sure it is the thing you want.

like image 81
Eric Fan Avatar answered Jan 27 '26 11:01

Eric Fan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!