Lock mechanism between a process on multiple machines

I have a C # application with NHibernate that needs to perform some operations on a SQL Server database.

Our goal is to run this application several times on the same computer, as well as on other machines.

In fact, the application inserts the row into the SQL table and checks if the first row with the minimum date is the row with the correct PID and the machine so that the application sets the lock and does the job.

We have problems with this logic because the application must also remove the lock of other applications if the application in which the lock is stored is broken.

Any hint at changing the architecture of the lock?

The problem is that the application can run on multiple computers.

+5
source share
2 answers

How to manage a lock in the database? You may have a table / stored procedure in which each executable instance is registered, gets a unique identifier and uses the stored procedure to lock & free. (Same method as preventing multiple logins for a single user from multiple machines).

+2
source

Or

  • Have a (server) process that manages the locks - all clients are registered and request locks from this server.
  • Pessimistic Autonomous Lock

I implemented it in both directions.

, , , ( db ). , , ReadCommited -

+2

All Articles