Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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
C# 如何从SSIS服务器获取运行包的集合?_C#_Sql Server_Ssis - Fatal编程技术网

C# 如何从SSIS服务器获取运行包的集合?

C# 如何从SSIS服务器获取运行包的集合?,c#,sql-server,ssis,C#,Sql Server,Ssis,在启动SSIS包之后,我尝试等待所有正在运行的包在SQL Server上完成,但我无法找到正确的方法。到目前为止,我掌握的代码是: var runningPackagesBefore = catalog.Executions.ToList(); // [..] logic to start the package while (true) { // get all packages that are new catalog.Executions.Refresh();

在启动SSIS包之后,我尝试等待所有正在运行的包在SQL Server上完成,但我无法找到正确的方法。到目前为止,我掌握的代码是:

var runningPackagesBefore = catalog.Executions.ToList();    

// [..] logic to start the package

while (true)
{
    // get all packages that are new
    catalog.Executions.Refresh();
    var newOperations = catalog.Executions.Except(runningPackagesBefore);

    // get all packages that are new, running and are in the same folder and project as the package
    var runningOperations =
        newOperations.Where(
            operation => operation.FolderName == catalogFolder.Name 
                && operation.ProjectName == project.Name 
                && operation.Status == Operation.ServerOperationStatus.Running);

    if (!runningOperations.Any())
    {
        break;
    }

    // [..] sleep and timeout logic here
}
调用catalog.Executions.Refresh()有时会导致死锁问题。文档中还说“不要直接引用此方法…”。
需要刷新,因为否则将缓存executions集合并返回0个新事务。当它在没有死锁的情况下运行时,它会正确返回正在运行的包的数量


因此,我试图找到一种方法来查看是否所有包都已完成运行。我运行的包是一个“主”包,它启动多个其他包。否则,我可以简单地从目录中获取执行ID和操作状态,但在这种情况下这是不可能的。

通过调用integrationservice并获取新目录解决了这个问题。这会自动刷新它:

// get all executions for this project that are currently running
var runningPackagesBefore = catalog.Executions.Select(operation => operation.Id).ToList();

// [..] logic to execute the package 

while (true)
{
    var integrationServices = new IntegrationServices(sqlConnection);
    Catalog refreshedCatalog = integrationServices.Catalogs[catalogName];

    // get all packages that are running
    var runningOperations = refreshedCatalog.Executions.Where(
        operation => operation.Status == Operation.ServerOperationStatus.Running);

    // get all packages that are new
    var newRunningOperations = runningOperations.Where(
        operation => !runningPackagesBefore.Contains(operation.Id));

    if (!newRunningOperations.Any())
    {
        break;
    }

    // [..] sleep and timeout logic here
}