Share via


Job.Start 方法 (String)

Runs the referenced job starting at the specified job step.

命名空间:  Microsoft.SqlServer.Management.Smo.Agent
程序集:  Microsoft.SqlServer.Smo(在 Microsoft.SqlServer.Smo.dll 中)

语法

声明
Public Sub Start ( _
    jobStepName As String _
)
用法
Dim instance As Job 
Dim jobStepName As String

instance.Start(jobStepName)
public void Start(
    string jobStepName
)
public:
void Start(
    String^ jobStepName
)
member Start : 
        jobStepName:string -> unit
public function Start(
    jobStepName : String
)

参数

  • jobStepName
    类型:System.String
    A String value that specifies the job step to start execution.

示例

The following code example creates a job and starts it at the specified job step.

C#

Server srv = new Server("(local)");
Job jb = new Job(srv.JobServer, "Test Job");
jb.Create();
JobStep jbstp = new JobStep(jb, "Test Job Step");
jbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess;
jbstp.OnFailAction = StepCompletionAction.QuitWithFailure;
jbstp.Create();
jb.ApplyToTargetServer(srv.Name);
jb.IsEnabled = true;
jb.Start("Test Job Step");

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$jb = new-object Microsoft.SqlServer.Management.Smo.Agent.Job($srv.JobServer, "Testrrt Job")
$jb.Create()
$jbstp = new-object Microsoft.SqlServer.Management.Smo.Agent.JobStep($jb, "Test Job Step")
$jbstp.OnSuccessAction = [Microsoft.SqlServer.Management.Smo.Agent.StepCompletionAction]::QuitWithSuccess
$jbstp.OnFailAction = [Microsoft.SqlServer.Management.Smo.Agent.StepCompletionAction]::QuitWithFailure
$jbstp.Create()
$jb.ApplyToTargetServer($srv.Name)
$jb.IsEnabled = $TRUE
$jb.Start("Test Job Step")

请参阅

参考

Job 类

Start 重载

Microsoft.SqlServer.Management.Smo.Agent 命名空间

其他资源

在 SQL Server 代理中计划自动管理任务

自动执行管理任务(SQL Server 代理)

sp_add_job (Transact-SQL)