sp_sjobcontrol

Description

Defines an interface for controlling running jobs.

Syntax

sp_sjobcontrol @name=’...’, @option=’...’

Parameters

name

The name or ID of the scheduled job, a job, or a runid to be controlled.

option

Specifies a comma-separated list of options and option_name=option_value pairs that define the action to perform.

  • terminate – instances of the job with the given name, ID, or runid are terminated.

  • enable – instances of the scheduled job with the given name or ID are enabled.

  • disable – instances of the scheduled job with the given name or ID are disabled. Any currently running jobs are unaffected.

  • run_now – schedules the job with the given name or ID to run now. However, there must be a nonconflicting scheduled job created for the corresponding job or sp_sjobcontrol returns an error.

  • all_users – allows users with the role js_admin_role to administer scheduled jobs owned by other users.

  • start_js – starts Job Scheduler.

  • stop_js – stops Job Scheduler and terminates any running jobs.

  • stop_js_wait – waits for running jobs to complete, and then stops Job Scheduler.

  • stop_js_timeout=minutes – waits a specified number of minutes, and then stops Job Scheduler, terminating any running jobs.

Returns

Returns 0 for success or an error code.

Examples

Example 1

The following example requests the JS Task and JS Agent to terminate the running job with runid 1532:

sp_sjobcontrol @name=’runid=1532’, @option=’terminate’

Example 2

The following example marks the scheduled job called “svr1_load_sales_data” so that it can be run now. The existing schedule is unchanged.

sp_sjobcontrol @name=’svr1_load_sales_data’, @option=’run_now’

Example 3

The following example disables all of the caller’s scheduled jobs that use the job called “check_user_logins”.

sp_sjobcontrol @name=’jname=check_user_logins’, @option=’disable’

Usage

By default, @name is the name, the ID, or a scheduled job. To specify the name or ID of a job or as a runid, the @name argument is prefixed with jname or runid.