How to kill a negative SPID (like SPID -2) in SQL Server?
Rarely this scenario will arise when most likely you see this negative SPID (most likely SPID -2) is blocking other transaction causing issues. If you try to kill it using normal KILL command, it will fail reporting below error:
Msg 6101, Level 16, State 1, Line 1
Process ID <SPID Number> is not a valid process ID. Choose a number between 1 and 2048
This is because of an orphaned distributed transaction ID.
Please follow below steps to kill it:
Step 1: -- Find the UOW Number
where req_spid = <SPID Number> -- <SPID Number> is -2 most likely.
Step 2: -- Copy the UOW number from Step one
KILL ‘<UOW Number>’
This will kill the negative SPID resolving the issue.
However please note following points:
1. For SPID -2, you may find multiple UOW numbers. Please start killing them one by one. Typically killing first UOW will resolve the issues. (ie. will kill all UOW and release the blocking)
2. If you do not find any valid UOW (In very rare case, you may find all UOW contain only 0 for SPID -2 and you can not kill them.), you may have to restart SQL Service and MS DTC Service for resolving the issue.
Long Term Fix: You should engage application team to figure out why orphaned distributed transaction ID related issue is generating and request them to fix the code as needed.