How do I cancel an app lock request in SQL Server?
Looking at the source of the sp_getapplock
wrapper proc, all the return values except for -999 originate from the underlying sys.xp_userlock
internal stored procedure. I'd bet the internal proc returns a -2 when the request is cancelled by an attention event (client query timeout or explict client query cancel). However, no further sp_getapplock
code executes after the batch is cancelled, including the RETURN
statement. Consequently, the -2 return code may be returned internally but there's no practical way for the client to get the value.
Assuming this theory is correct, there isn't any value in translating to -2 to more descriptive message since it's the client that cancelled the request in the first place.
I'll leave it to Paul to confirm this by stepping through the SQL database engine code with a debugger :-)