Compartilhar via


Classe Job

The Job class represents a Microsoft SQL Server Agent job.

Hierarquia de herança

System.Object
  Microsoft.SqlServer.Management.Smo.SmoObjectBase
    Microsoft.SqlServer.Management.Smo.SqlSmoObject
      Microsoft.SqlServer.Management.Smo.NamedSmoObject
        Microsoft.SqlServer.Management.Smo.Agent.AgentObjectBase
          Microsoft.SqlServer.Management.Smo.Agent.Job

Namespace:  Microsoft.SqlServer.Management.Smo.Agent
Assembly:  Microsoft.SqlServer.Smo (em Microsoft.SqlServer.Smo.dll)

Sintaxe

'Declaração
Public NotInheritable Class Job _
    Inherits AgentObjectBase _
    Implements IAlterable, ICreatable, IDroppable, IRenamable,  _
    IScriptable
'Uso
Dim instance As Job
public sealed class Job : AgentObjectBase, IAlterable, 
    ICreatable, IDroppable, IRenamable, IScriptable
public ref class Job sealed : public AgentObjectBase, 
    IAlterable, ICreatable, IDroppable, IRenamable, IScriptable
[<SealedAttribute>]
type Job =  
    class 
        inherit AgentObjectBase 
        interface IAlterable 
        interface ICreatable 
        interface IDroppable 
        interface IRenamable 
        interface IScriptable 
    end
public final class Job extends AgentObjectBase implements IAlterable, ICreatable, IDroppable, IRenamable, IScriptable

O tipo Job expõe os membros a seguir.

Construtores

  Nome Descrição
Método público Job() Initializes a new instance of the Job class.
Método público Job(JobServer, String) Initializes a new instance of the Job class on the specified instance of Microsoft SQL Server Agent and with the specified name.
Método público Job(JobServer, String, Int32) Initializes a new instance of the Job class on the specified instance of SQL Server Agent and with the specified name and category

Início

Propriedades

  Nome Descrição
Propriedade pública Category Gets or sets the category to which the job belongs.
Propriedade pública CategoryID Gets the ID value that uniquely identifies the job category.
Propriedade pública CategoryType Gets or sets the type of category, with respect to local or multiserver jobs.
Propriedade pública CurrentRunRetryAttempt Gets the number of times Microsoft SQL Server Agent has attempted to run the job unsuccessfully.
Propriedade pública CurrentRunStatus Gets the current execution status of the job.
Propriedade pública CurrentRunStep Gets information about the job step that is currently running.
Propriedade pública DateCreated Gets the date and time when the job was created.
Propriedade pública DateLastModified Gets the date and time when the job was last modified.
Propriedade pública DeleteLevel Gets or sets the completion action that determines whether to delete the job definition when the job finishes execution.
Propriedade pública Description Gets or sets the textual description of the job.
Propriedade pública EmailLevel Gets or sets the completion action that determines whether to send an e-mail notification to an operator when the job finishes execution.
Propriedade pública EventLogLevel Gets or sets the completion action that determines whether to generate an operating system event log entry when the job finishes execution.
Propriedade pública HasSchedule Gets the Boolean property value that specifies whether the job has at least one schedule.
Propriedade pública HasServer Gets the Boolean property value that specifies whether the job has a target server assigned for multiple-server operations.
Propriedade pública HasStep Gets the Boolean property value that specifies whether the job has at least one job step.
Propriedade pública IsEnabled Gets or sets the Boolean property value that specifies whether the job is enabled.
Propriedade pública JobID Gets the job ID value.
Propriedade pública JobSchedules Gets a collection of JobSchedule objects that represent the schedules assigned to the job.
Propriedade pública JobSteps Gets a collection of JobStep objects that represent the job steps defined for the job.
Propriedade pública JobType Gets the job type, which specifies whether the job is local or multiserver.
Propriedade pública LastRunDate Gets the date and time when the job was last run.
Propriedade pública LastRunOutcome Gets the result of the job from the last time it completed execution.
Propriedade pública Name Gets or sets the name of the Job. (Substitui NamedSmoObject.Name.)
Propriedade pública NetSendLevel Gets or sets the completion action that determines whether to net-send a notification to an operator when the job finishes execution.
Propriedade pública NextRunDate Gets the date and time when the job is next scheduled to run.
Propriedade pública NextRunScheduleID Gets the ID value of the schedule that is responsible for the next execution of the job.
Propriedade pública OperatorToEmail Gets or sets the operator that receives notification by e-mail when the job finishes execution.
Propriedade pública OperatorToNetSend Gets or sets the operator that receives a net-send notification when the job finishes execution.
Propriedade pública OperatorToPage Gets or sets the operator that receives a pager notification when the job finishes execution.
Propriedade pública OriginatingServer Gets the name of the server that is acting as the master server in a multiserver job.
Propriedade pública OwnerLoginName Gets or sets the owner of the job.
Propriedade pública PageLevel Gets or sets the completion action that determines whether to send a pager notification to an operator when the job finishes execution.
Propriedade pública Parent Gets or sets the JobServer object that is the parent of the Job object.
Propriedade pública Properties Gets a collection of Property objects that represent the object properties. (Herdado de SqlSmoObject.)
Propriedade pública StartStepID Gets or sets the ID value of the first job step in the sequence to be executed.
Propriedade pública State Gets the state of the referenced object. (Herdado de SmoObjectBase.)
Propriedade pública Urn Gets the Uniform Resource Name (URN) address value that uniquely identifies the object. (Herdado de SqlSmoObject.)
Propriedade pública UserData Gets or sets user-defined data associated with the referenced object. (Herdado de SmoObjectBase.)
Propriedade pública VersionNumber Gets a system-maintained value that is incremented every time the job is modified.

Início

Métodos

  Nome Descrição
Método público AddSharedSchedule Adds a shared schedule to the Microsoft SQL Server Agent job.
Método público Alter Updates any Job object property changes on an instance of Microsoft SQL Server. 
Método público ApplyToTargetServer Adds a server to the list of target servers maintained for the referenced Microsoft SQL Server Agent job.
Método público ApplyToTargetServerGroup Adds one or more servers to the list of target servers maintained for the referenced Microsoft SQL Server Agent job.
Método público Create Creates a job on the instance of Microsoft SQL Server as defined by the Job object.
Método público DeleteJobStepLogs(DateTime) Deletes job step log files that are older than the specified date.
Método público DeleteJobStepLogs(Int32) Deletes job step log files that are larger that the specified log ID number.
Método público Discover Discovers a list of type Object. (Herdado de SqlSmoObject.)
Método público Drop() Removes an existing job.
Método público Drop(Boolean) Removes an existing job.
Método público EnumAlerts Enumerates a list of Agent alerts that cause automated execution of the referenced job.
Método público EnumHistory() Enumerates a list of execution history associated with the referenced job.
Método público EnumHistory(JobHistoryFilter) Enumerates a list of execution history associated with the referenced job.
Método público EnumJobStepLogs() Enumerates a list of job step log files for the referenced job.
Método público EnumJobStepLogs(Int32) Enumerates a list of job step log files for the job step with the specified ID value.
Método público EnumJobStepLogs(String) Enumerates a list of job step log files for the job step with the specified name.
Método público EnumJobStepsByID Returns an array of JobStep objects that belong to the referenced job and that are ordered by ID value.
Método público EnumTargetServers Enumerates a list of execution target servers that have been assigned to the referenced job.
Método público Equals (Herdado de Object.)
Método protegido FormatSqlVariant Formats an object as SqlVariant type. (Herdado de SqlSmoObject.)
Método protegido GetContextDB Gets the context database that is associated with this object. (Herdado de SqlSmoObject.)
Método protegido GetDBName Gets the database name that is associated with the object. (Herdado de AgentObjectBase.)
Método público GetHashCode (Herdado de Object.)
Método protegido GetPropValue Gets a property value of the SqlSmoObject object. (Herdado de SqlSmoObject.)
Método protegido GetPropValueOptional Gets a property value of the SqlSmoObject object. (Herdado de SqlSmoObject.)
Método protegido GetPropValueOptionalAllowNull Gets a property value of the SqlSmoObject object. (Herdado de SqlSmoObject.)
Método protegido GetServerObject Gets the server of the SqlSmoObject object. (Herdado de SqlSmoObject.)
Método público GetType (Herdado de Object.)
Método público Initialize() Initializes the object and forces the properties be loaded. (Herdado de SqlSmoObject.)
Método público Initialize(Boolean) Initializes the object and forces the properties be loaded. (Herdado de SqlSmoObject.)
Método público Invoke Runs the job.
Método protegido IsObjectInitialized Verifies whether the object has been initialized. (Herdado de SqlSmoObject.)
Método protegido IsObjectInSpace Verifies whether the object is isolated or connected to the instance of SQL Server. (Herdado de SqlSmoObject.)
Método público PurgeHistory Removes system records maintaining execution history for the referenced job.
Método público Refresh Refreshes the object and retrieves properties when the object is next accessed. (Herdado de SqlSmoObject.)
Método público RemoveAllJobSchedules() Removes all shared and unshared schedules from the job.
Método público RemoveAllJobSchedules(Boolean) Removes all unused schedules from the job.
Método público RemoveAllJobSteps Removes all the job steps associated with the job.
Método público RemoveFromTargetServer Removes an execution target server from the list of target servers maintained for a job.
Método público RemoveFromTargetServerGroup Removes a group of execution target servers from the list of target servers maintained for a job.
Método público RemoveSharedSchedule(Int32) Removes the specified shared schedule from the job.
Método público RemoveSharedSchedule(Int32, Boolean) Removes the specified shared schedule from the job and keeps unused schedules.
Método público Rename Renames the job.
Método público Script() Generates a Transact-SQL script that can be used to re-create the Microsoft SQL Server Agent job.
Método público Script(ScriptingOptions) Generates a Transact-SQL script that can be used to re-create the Microsoft SQL Server Agent job as specified by the scripting options.
Método protegido SetParentImpl Sets the parent of the SqlSmoObject to the newParent parameter. (Herdado de SqlSmoObject.)
Método público Start() Runs the referenced job.
Método público Start(String) Runs the referenced job starting at the specified job step.
Método público Stop Stops executing the referenced job.
Método público ToString Returns a String that represents the referenced object. (Herdado de SqlSmoObject.)
Método público Validate Validates the state of an object. (Herdado de SmoObjectBase.)

Início

Eventos

  Nome Descrição
Evento público PropertyChanged Represents the event that occurs when a property is changed. (Herdado de SqlSmoObject.)
Evento público PropertyMetadataChanged Represents the event that occurs when property metadata changes. (Herdado de SqlSmoObject.)

Início

Implementações de interfaces explícitas

  Nome Descrição
Implementações de interfaces explícitasMétodo privado IAlienObject.Discover Discovers any dependencies. Não referencie esse membro diretamente no código. Ele dá suporte à infraestrutura do SQL Server. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.GetDomainRoot Returns the root of the domain. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.GetParent Gets the parent of this object. Não referencie esse membro diretamente no código. Ele dá suporte à infraestrutura do SQL Server. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.GetPropertyType Gets the type of the specified property. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.GetPropertyValue Gets the value of the specified property. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.GetUrn Gets the Unified Resource Name (URN) of the object. Não referencie esse membro diretamente no código. Ele dá suporte à infraestrutura do SQL Server. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.Resolve Gets the instance that contains the information about the object from the Unified Resource Name (URN) of the object. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.SetObjectState Sets the object state to the specified SfcObjectState value. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado IAlienObject.SetPropertyValue Sets the property value. (Herdado de SqlSmoObject.)
Implementações de interfaces explícitasMétodo privado ISfcPropertyProvider.GetPropertySet Gets the interface reference to the set of properties of this object. (Herdado de SqlSmoObject.)

Início

Comentários

To get or set Job object properties, users must be a member of the SQLAgentUserRole database role on the MSDB database, or be the owner of the job, or be a member of the sysadmin fixed server role.

To create a job, users must be a member of the SQLAgentUserRole, SQLAgentReaderRole, and SQLAgentOperatorRole database roles on the MSDB database, or be a member of the sysadmin fixed server role.

To drop a job, users must be a member of the SQLAgentUserRole database role on the MSDB database, or be the owner of the job, or be a member of the sysadmin fixed server role.

Thread Safety

Qualquer membro público estático (Compartilhado no Microsoft Visual Basic) desse tipo é seguro para operações multi-threaded. Não há garantia de que qualquer membro de instância seja seguro para threads.

Exemplos

Agendando tarefas administrativas automáticas no SQL Server Agent

Segurança de thread

Qualquer membro público static (Shared no Visual Basic) desse tipo é seguro para threads. Não há garantia de que qualquer membro de instância seja seguro para threads.

Consulte também

Referência

Namespace Microsoft.SqlServer.Management.Smo.Agent

Outros recursos

Tarefas de administração automatizadas (SQL Server Agent)

sp_add_job (Transact-SQL)