There are different ways to stop the SQL jobs, we can use SQL Server Management Studio or we can use Transact SQL command to stop SQL jobs also we can use Kill process for special cases to stop the SQL job.
1-SQL Server Management Studio:
a. Open the SQL Server Management Studio
b. in the Object Explore select SQL Server Agent and expand this node then select/expand Jobs node and select the Job name and right click and select Stop Job
2-Use Transact SQL command:
sp_stop_job
[@job_name =] 'job_name'
| [@job_id =] job_id
| [@originating_server =] 'master_server'
| [@server_name =] 'target_server'
When SQL Server Agent receives the stop notification, it waits for the job step that is currently running to finish before it processes the cancel request. Some long-running Transact-SQL statements such as BACKUP, RESTORE, and some DBCC commands can take a long time to finish. When these are running, it may take awhile before the job is canceled. Stopping a job causes a "Job Canceled" entry to be recorded in the job history.
If a job is currently executing a step of type CmdExec or PowerShell, the process being run (for example, MyProgram.exe) is forced to end prematurely. Premature ending can result in unpredictable behavior such as files in use by the process being held open. Consequently, sp_stop_job should be used only in extreme circumstances if the job contains steps of type CmdExec or PowerShell.
Pasted from <http://msdn.microsoft.com/en-us/library/ms182793.aspx>
USE msdb ;
GO
EXEC dbo.sp_stop_job
N'Weekly Sales Data Backup' ;
GO
3-Kill Process:
sometimes using the SQL Server Management Studio or we can use Transact SQL command failed to stop the SQL jobs (specially if the Job was running for long periods continually and it executing a step of type CmdExec or PowerShell) in this case we can use Kill command to terminate the process:
1. Find the current status of the SQL job by run
EXEC dbo.sp_help_job @job_name = N'Job Name'
2. From the first step you will get the SQL job ID (job_id)
e.g. 85289469-7A84-41F2-A761-B73E239B7A1C
3. Run sp_who2 active which shows all the sessions that are currently established in the database. These are denoted as SPID’s, or Server process Id’s, in the result of sp_who2 active under ProgramName field look for SQL Job ID which you got it in step (2) you will find some thing like:
SQLAgent - TSQL JobStep (Job 0x69942885847AF241A761B73E239B7A1C : Step 1) after you allocate the exact row noted down the SPID of that row (e.g. 172).
4. open new query use Kill command to stop the job
kill 172

No comments:
Post a Comment