Saturday, July 12, 2014

Stop SQL job from commands

Jobs are not stopping when click on stop button of job. so I used follwing command to stop it.



SELECT j.name as jobname
   
              , j.*,ja.*
FROM msdb.dbo.sysjobactivity ja
JOIN msdb.dbo.sysjobs j
    ON ja.job_id = j.job_id
WHERE ja.session_id = (SELECT TOP 1 session_id FROM msdb.dbo.syssessions ORDER BY agent_start_date DESC)
AND start_execution_date is not null
AND stop_execution_date is null;

Step 2-> Copy all rows in Excel.

Step 3-> look the DB name, Job execution time, Job started date etc.

Step 4-> Now select correct SPID and stop it.

--sp_who2
--kill -58-  

Where 58 Is SPID which I want to stop.

No comments: