2014-12-24 4 views
0

SSIS 패키지를 시작한 후 실행중인 패키지가 모두 SQL Server에서 완료 될 때까지 기다리려고하지만 올바른 방법을 찾을 수 없습니다. 내가 지금까지 가지고있는 코드는 다음과 같습니다 때때로SSIS 서버에서 실행중인 패키지를 가져 오는 방법은 무엇입니까?

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() 호출 원인 교착 상태 문제. 설명서에는 "이 메서드를 직접 참조하지 마십시오."라고 나와 있습니다.
그렇지 않으면 실행 컬렉션이 캐시되고 0 개의 새 트랜잭션이 반환되므로 새로 고침이 필요합니다. 그리고 교착 상태없이 실행되면 실행중인 패키지의 양이 올바르게 반환됩니다.

그래서 모든 패키지가 실행 완료되었는지 확인하는 방법을 찾고 있습니다. 제가 실행중인 패키지는 여러 다른 패키지를 시작하는 "마스터"패키지입니다. 그렇지 않으면 단순히 실행 ID를 얻고 카탈로그에서 작업 상태를 가져올 수 있지만이 경우 불가능합니다.

답변

0

통합 서비스를 호출하고 새 카탈로그를 가져옴으로써 해결되었습니다. 그러면 자동으로 새로 고침됩니다.

// 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 
} 
관련 문제