SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Killing A Service Broker SPID

Killing a SPID shouldn’t be complicated. Execute the command KILL [SPID] and that should kill the session. But there are situations where a SPID that is spawned by the Service Broker stays alive even after the queue is stuck in limbo.

No matter how many times you kill the SPID, it will find a way to re-connect and will continue to sap your CPU. You would think that a server reboot would kill the SPID as the reboot will restart the service. But, no, the SPID will restart again. Setting the database to SINGLE_USER? Nope. That does not work either.

Ok, this is more of a note to self than a real blog post.

Here’s a quick way to KILL a SPID spawned by a Service Broker queue.

Run sp_whoisactive to check the program_name of the running SPID. The program name should give you the identification of the running process.

Find Queue Name

SELECT qs.name,
FROM sys.dm_broker_queue_monitors qm
JOIN sys.service_queues qs
ON qm.queue_id = qs.object_id

Then, get all the Conversation_Handle of the Queue

SELECT Conversation_Handle FROM dbo.MyQueueNameHere

That gives us all the Conversation_Handle of the Queue, then we can then End the conversations, like,

END CONVERSATION 'xxxxxxx-xxxx-xxx-xxx-xxxxxxxxxx'

Now we can go back to the active tasks of the Queue to get all the SPIDs

SELECT SPID FROM sys.dm_broker_activated_tasks

Then, based on that list, we can then issue the KILL command.

KILL xx;

Again, you cannot just KILL SPID or end any Service Broker conversation willy-nilly. You have to do your due diligence before deciding to kill the SPIDs or end the Service Broker tasks.

Here’s a list of useful DM and Catalog Views that are related to Service Broker:









You can do something like this to get more info about the queues and the tasks or processes associated with them

SELECT at.procedure_name,







FROM sys.dm_broker_activated_tasks AS at

JOIN sys.dm_exec_sessions s

ON at.spid = s.session_id

The post Killing A Service Broker SPID appeared first on SQL, Code, Coffee, Etc..

Marlon Ribunal - SQL, Code, Coffee, etc.

I'm passionate about SQL Server. But I feel like I haven't reached my full potential yet. So, this is my mission: My purpose is to help people in their pursuit of growth and development; and, thereby, help myself realize my full potential as a professional, husband, father, christian, and human being.
My online presences include: Tech Blog: Marlon Ribunal - SQL, Code, Coffee, etc. Productivity & GTD Hack Blog: Productivity Bits Twitter: @MarlonRibunal


Leave a comment on the original post [marlonribunal.com, opens in a new window]

Loading comments...