Creating a cross-computer mutex using SQL Server

Viewed 4340

I have a few computers using the same database (SQL Server 2008)

I'm trying to synchronize a task between all these computers using the database.

Each task is represented by a guid that is the lock-id (if comparing to Mutex, that would be the Mutex name)

I have a few thoughts, but I think they are kind of hacks, and was hoping someone here would have a better solution:

  1. Create a new table "Locks" each row consists of a guid, lock the table row exclusively in a transaction - and complete/revert the transaction when finished.
  2. use the sp_getapplock in a transaction where the lock name is the lock-id guid

I think that holding a transaction running is not so good... I thought maybe there's a solution that does not require me to hold an open transaction or session?

3 Answers
Related