프로그래밍 방식으로 태스크 연결

개체 모델에서 PrecedenceConstraint 클래스가 나타내는 선행 제약 조건은 패키지에서 Executable 개체가 실행되는 순서를 설정합니다. 선행 제약 조건을 사용하면 패키지의 컨테이너 및 태스크 실행이 이전 태스크 또는 컨테이너의 실행 결과에 따라 결정되도록 할 수 있습니다. 선행 제약 조건은 컨테이너 개체에서 PrecedenceConstraints 컬렉션의 Add 메서드를 호출하여 Executable 개체 쌍 간에 설정됩니다. 두 개의 실행 개체 사이에 제약 조건을 만든 후 Value 속성을 설정하여 제약 조건에 정의된 두 번째 실행 파일을 실행하기 위한 조건을 지정합니다.

다음 표에서 설명하는 것처럼 EvalOp 속성에 지정하는 값에 따라 단일 선행 제약 조건에 제약 조건과 식을 모두 사용할 수 있습니다.

EvalOp 속성 값

설명

Constraint

실행 결과에 따라 제약 조건이 지정된 컨테이너 또는 태스크의 실행 여부가 결정되도록 지정합니다. PrecedenceConstraintValue 속성을 DTSExecResult 열거형에서 원하는 값으로 설정합니다.

Expression

식의 값에 따라 제약 조건이 지정된 컨테이너 또는 태스크의 실행 여부가 결정되도록 지정합니다. PrecedenceConstraintExpression 속성을 설정합니다.

ExpressionAndConstraint

제약 조건 결과가 발생해야 하며 식에서 제약 조건이 지정된 컨테이너 또는 태스크의 실행을 평가해야 하도록 지정합니다. PrecedenceConstraintValueExpression 속성을 모두 설정하고 해당 LogicalAnd 속성을 true로 설정합니다.

ExpressionOrConstraint

제약 조건 결과가 발생해야 하거나 식에서 제약 조건이 지정된 컨테이너 또는 태스크의 실행을 평가해야 하도록 지정합니다. PrecedenceConstraintValueExpression 속성을 모두 설정하고 해당 LogicalAnd 속성을 false로 설정합니다.

다음 코드 예제에서는 패키지에 두 개의 태스크를 추가하는 방법을 보여 줍니다. 두 태스크 사이에는 PrecedenceConstraint가 만들어지므로 첫 번째 태스크가 완료될 때까지 두 번째 태스크는 실행되지 않습니다.

using System;
using Microsoft.SqlServer.Dts.Runtime;

namespace Microsoft.SqlServer.Dts.Samples
{
  class Program
  {
    static void Main(string[] args)
    {
      Package p = new Package();

      // Add a File System task.
      Executable eFileTask1 = p.Executables.Add("STOCK:FileSystemTask");
      TaskHost thFileHost1 = eFileTask1 as TaskHost;

      // Add a second File System task.
      Executable eFileTask2 = p.Executables.Add("STOCK:FileSystemTask");
      TaskHost thFileHost2 = eFileTask2 as TaskHost;

      // Put a precedence constraint between the tasks.
      // Set the constraint to specify that the second File System task cannot run
      // until the first File System task finishes.
      PrecedenceConstraint pcFileTasks = 
        p.PrecedenceConstraints.Add((Executable)thFileHost1, (Executable)thFileHost2);
      pcFileTasks.Value = DTSExecResult.Completion;
    }
  }
}
Imports Microsoft.SqlServer.Dts.Runtime

Module Module1

  Sub Main()

    Dim p As Package = New Package()
    ' Add a File System task.
    Dim eFileTask1 As Executable = p.Executables.Add("STOCK:FileSystemTask")
    Dim thFileHost1 As TaskHost = CType(eFileTask1, TaskHost)

    ' Add a second File System task.
    Dim eFileTask2 As Executable = p.Executables.Add("STOCK:FileSystemTask")
    Dim thFileHost2 As TaskHost = CType(eFileTask2, TaskHost)

    ' Put a precedence constraint between the tasks.
    ' Set the constraint to specify that the second File System task cannot run
    ' until the first File System task finishes.
    Dim pcFileTasks As PrecedenceConstraint = _
      p.PrecedenceConstraints.Add(CType(thFileHost1, Executable), CType(thFileHost2, Executable))
    pcFileTasks.Value = DTSExecResult.Completion

  End Sub

End Module
Integration Services 아이콘(작은 아이콘) Integration Services 관련 최신 정보 얻기

Microsoft의 최신 다운로드, 아티클, 예제 및 비디오와 커뮤니티의 정선된 솔루션을 보려면 MSDN 또는 TechNet의 Integration Services 페이지를 방문하십시오.

이러한 업데이트에 대한 자동 알림을 받으려면 해당 페이지에서 제공하는 RSS 피드를 구독하십시오.