How to block a record when two participants try to access it?

I have such a scenario

My .Net2.0 environment, VS 2008, web application

I need to lock the record when two elements are trying to access at the same time.

We can do this in two ways:

  • Upon completion (by placing the session identifier and writing a unique number in the dictionary and saving it as a static or application variable), we will exit when the answer leaves this page, the client is not connected after the "Send" button is pressed, and the session is disconnected.

  • By (recording lock in the database itself - you need to study - my team member is watching).

Are there any other ways and do I need to look for other ways at each step?

Am I missing any conditions?

+3
source share
3 answers

You do not block records for clients, because blocking a record for anything more than a few milliseconds is the most dangerous thing that can be done in the database. Instead, you should use Optimistic Concurrency : you detect whether the record has been modified since the last read and retry of the transaction (for example, open the screen to the user). How it is actually implemented will depend on which database technology you are using (ADO.Net, DataSets, Linq, EF, etc.).

- , , : , "", . . "" , "" "" - .

din P EAA: .

+6

SQL-, !!! SQL- , . , Transaction.

0

. , . IsInUse true, . , - .. , , , IsInUse False .

0

Source: https://habr.com/ru/post/1753107/


All Articles