Job Object (SQL-DMO)

The Job object exposes the attributes of a single SQL Server Agent job.

Remarks

A SQL Server Agent job is a scheduled series of executable steps. Jobs are typically used to automate administrative tasks performed against a Microsoft® SQL Server™ database. With SQL Server version 7.0, jobs can contain multiple steps with branch logic based on the success or failure of any individual step. A SQL Server 7.0 job can contain one or more schedules setting run times for the task defined by the steps of the job.

With the Job object, you can:

The Name property of a Job object uses the SQL Server data type sysname. The string must be unique for all jobs defined on a server running SQL Server.

Using SQL-DMO and the Job object, you must create a SQL Server Agent job before you can add job steps to it. A job must have at least one job step and a target server to be executable by SQL Server Agent.

After a SQL Server Agent job has at least one step and an execution target, you can use the Start method of the Job object to execute the job. To schedule the job for execution by SQL Server Agent, use the JobSchedule object.

To create a SQL Server Agent job

  1. Create a Job object.
  2. Set the Name property.
  3. Add the Job object to the Jobs collection of a connected JobServer object to create the SQL Server Agent job.

To complete the definition of a SQL Server Agent job

  1. Use the JobStep object to define a job step.
  2. Add the JobStep object to the JobSteps collection of the Job object.
  3. Set the StartStepID property of the Job object to the value of the StepID property of the JobStep added.
  4. Use the ApplyToTargetServer or ApplyToTargetServerGroup method of the Job object to set the execution target for the SQL Server Agent job. Use the string (local) to indicate the server on which the job is located.
Methods
AddStepToJob Method PurgeHistory Method
ApplyToTargetServer Method Refresh Method
ApplyToTargetServerGroup Method Remove Method (Objects)
BeginAlter Method RemoveAllJobSchedules Method
CancelAlter Method RemoveAllJobSteps Method
DoAlter Method RemoveFromTargetServer Method
EnumAlerts Method RemoveFromTargetServerGroup Method
EnumHistory Method Script Method
EnumTargetServers Method Start Method (Job)
Invoke Method Stop Method

Properties
Category Property LastRunOutcome Property
CurrentRunRetryAttempt Property LastRunTime Property
CurrentRunStatus Property Name Property
CurrentRunStep Property NetSendLevel Property
DateCreated Property NextRunDate Property
DateLastModified Property NextRunScheduleID Property
DeleteLevel Property NextRunTime Property
Description Property OperatorToEmail Property
EmailLevel Property OperatorToNetSend Property
Enabled Property OperatorToPage Property
EventlogLevel Property OriginatingServer Property
HasSchedule Property Owner Property (Job, JobFilter)
HasServer Property PageLevel Property
HasStep Property StartStepID Property
JobID Property Type Property (Job, JobFilter)
LastRunDate Property VersionNumber Property

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.