Cancel Query in remote ssms from ssms in my pc [closed]
-
11-12-2020 - |
Question
We connect to our customer's database server with vpn. Sometimes we manage Sql server to connect database server or to connect with ssms in our pc's.
I executed a query with ssms in database server, then the connection has gone down. I have tried to connect many times but failed. I have to cancel this query.
I can connect with ssms in my pc's.
Can I cancel query with ssms in my pc?
Solution
Step 1: Get query session id using below query
SELECT sqltext.TEXT,
req.session_id,----- SPID
req.status,
req.command,
req.cpu_time,
req.total_elapsed_time,req.start_time,db_name(database_id) DatabaseName
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
where [status] <> 'background'
and command<> 'TASK MANAGER'
Step 2: use kill command to kill the process execution
Kill(53) -- KIll (SPID)
OTHER TIPS
Use KILL (SPID) to kill the query.
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange