0

I am the DBA for an application that uses the sp_getapplock stored procedure call to perform some specific funcitonality. Occasionally, for some unknown reason, perhaps application bug, gremlins, or other unknown error, the lock is not released. I can programmatically determine whether one of these locks is in a frozen state by looking in the application DB. I would like to call sp_releaseapplock to free the lock under certain circumstances, but I cannot figure out where the associated resource_name used in the corresponding sp_getapplock call is stored in the system DMVs.

Since the application uses a random resource name each time it is called, I cannot hardcode the sp_releaselock call. How do I determine through the DMVs the resource_name associated with an entry in the sys.dm_tran_locks table?

Robert Sievers
  • 1,277
  • 10
  • 15
  • According to the documentation, *The specified name is hashed internally into a value that can be stored in the SQL Server lock manager* - so it's not going to stored as the provided string value. – Stu Jun 21 '22 at 20:45
  • Yes, I saw that in the docs, which precipitated the question of whether it is possible to get the unhashed value. – Robert Sievers Jun 21 '22 at 20:48
  • One of the points of hashing is it's a one way process, @RobertSievers . – Thom A Jun 21 '22 at 20:53
  • Sounds like the session is not ending, which indicates poor usage of client-side drivers. You *must* make sure to close the session, by using something like a `finally` or a `catch` block to ensure that. Once you close the session the lock should be released. – Charlieface Jun 21 '22 at 22:21

0 Answers0