Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
等待执行SSIS作业_Ssis_Powershell 2.0 - Fatal编程技术网

等待执行SSIS作业

等待执行SSIS作业,ssis,powershell-2.0,Ssis,Powershell 2.0,我使用下面的代码从ssis运行ssis作业,该作业运行良好,但我希望在运行作业后,它应该等待作业完成,然后继续 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") |Out-Null; [Microsoft.SqlServer.Management.Smo.Server]$sqlServer = New-Object Microsoft.SqlServer.Management.Smo.Serv

我使用下面的代码从ssis运行ssis作业,该作业运行良好,但我希望在运行作业后,它应该等待作业完成,然后继续

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") |Out-Null;
[Microsoft.SqlServer.Management.Smo.Server]$sqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server $HostName;

if([String]::IsNullOrEmpty($sqlServer.Urn))
{
    Write-Host "`nThe hostname provided is not a valid SQL Server instance.  Did you mistype the alias or forget to add the instance name?`n";
    Exit;
}
else
{ 
    [String]$databaseInstance = $sqlServer.JobServer.Urn.Value.Substring($sqlServer.JobServer.Urn.Value.IndexOf("'") + 1, `
    $sqlServer.JobServer.Urn.Value.IndexOf("'", ($sqlServer.JobServer.Urn.Value.IndexOf("'")) `
        - ($sqlServer.JobServer.Urn.Value.IndexOf("'"))));
}

Write-Host "Enumerating jobs on server ...";

[Microsoft.SqlServer.Management.Smo.Agent.Job]$job = ($sqlServer.JobServer.Jobs | ? { $_.Name -eq $JobName });

if($job -eq $null)
{
    Write-Host "`nNo such job on the server.`n";
    Exit;
}

# Finally invoke the job.  Use the job history (in SSMS) to verify the success of the job.
Write-Host "Executing job (the script doesn't wait for the job to finish but it should)...`n`n";
$job.Start();
*$job.Start()之后如何等待;看到工作完成,以便我可以继续进行

我正在执行下面的代码,但它不能正常工作,有什么帮助吗

   [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")

$server = new-object "Microsoft.SqlServer.Management.Smo.Server" "ServerName"
$job = $server.JobServer.Jobs["YourJobName"]
$now = Get-Date
do
{
 Start-Sleep -Seconds 1
 $job.Refresh()
 $jobstat = $job | select CurrentRunStatus
 $stat = $jobstat.CurrentRunStatus
 WRITE-HOST $stat
}

while($stat -eq "Executing")

$job | select Name,CurrentRunStatus,LastRunDate

启动SQL代理作业是一个异步事件。您无法将进度消息推送回您。正如Tab Alleman所评论的,您需要轮询msdb作业表以确定代理是否仍在运行


也就是说,您需要通过代理启动作业吗?如果您只是在运行一个包,请使用API启动包并观察事件,直到它完成/失败/等等。

我不知道powershell,但您不能编写一个等待(休眠)n秒然后查询作业历史记录表以查看作业是否完成的循环吗?继续循环,直到得到作业完成的结果。如果您有一个任务必须等待第一个作业完成,为什么不将其作为作业中的第二个任务?同时,我已经编写了以下代码#Load Assemblys[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.ConnectionInfo”)[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”)$server=new object“Microsoft.SqlServer.Management.Smo.server”“server”$job=$server.JobServer.Jobs[$JobName]$now=Get Date$jobstat=$job |如果($jobstat-eq'running'),请选择CurrentRunStatus{WRITE-HOST'作业正在运行#尚未编码}