以程式設計的方式連接資料流程元件

在將元件加入資料流程工作後,就可以連接元件以建立執行樹狀目錄,以代表從來源經過轉換到目的地的資料流程。您使用 IDTSPath100 物件以連接資料流程中的元件。

建立路徑

呼叫 MainPipe 介面中 PathCollection 屬性的 New 方法,以建立新路徑並將它加入資料流程工作中的路徑集合。此方法會傳回中斷連接的新 IDTSPath100 物件,您可用以連接兩個元件。

呼叫 AttachPathAndPropagateNotifications 方法以連接路徑並通知元件參與已連接它們的路徑。這個方法會以參數的方式接受上游元件的 IDTSOutput100 以及下游元件的 IDTSInput100。依預設,呼叫元件的 ProvideComponentProperties 方法會為具有輸入的元件建立單一輸入,並為具有輸出的元件建立單一輸出。下列範例使用目的地之來源與輸入的這個預設輸出。

下一個步驟

在您建立兩個元件之間的路徑之後,下一個步驟就是要對應下游元件中的輸入資料行,這將在下一主題中討論:以程式設計方式選取輸入資料行

範例

下列程式碼範例示範如何在兩個元件之間建立路徑。

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

namespace Microsoft.SqlServer.Dts.Samples
{
  class Program
  {
    static void Main(string[] args)
    {
      Package package = new Package();
      Executable e = package.Executables.Add("STOCK:PipelineTask");
      TaskHost thMainPipe = e as TaskHost;
      MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;

      // Create the source component.  
      IDTSComponentMetaData100 source =
        dataFlowTask.ComponentMetaDataCollection.New();
      source.ComponentClassID = "DTSAdapter.OleDbSource";
      CManagedComponentWrapper srcDesignTime = source.Instantiate();
      srcDesignTime.ProvideComponentProperties();

      // Create the destination component.
      IDTSComponentMetaData100 destination =
        dataFlowTask.ComponentMetaDataCollection.New();
      destination.ComponentClassID = "DTSAdapter.OleDbDestination";
      CManagedComponentWrapper destDesignTime = destination.Instantiate();
      destDesignTime.ProvideComponentProperties();

      // Create the path.
      IDTSPath100 path = dataFlowTask.PathCollection.New();
      path.AttachPathAndPropagateNotifications(source.OutputCollection[0],
        destination.InputCollection[0]);
    }
  }

}

Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Module Module1

  Sub Main()

    Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _
      New Microsoft.SqlServer.Dts.Runtime.Package()
    Dim e As Executable = package.Executables.Add("STOCK:PipelineTask")
    Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _
      CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)
    Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

    ' Create the source component.  
    Dim source As IDTSComponentMetaData100 = _
      dataFlowTask.ComponentMetaDataCollection.New()
    source.ComponentClassID = "DTSAdapter.OleDbSource"
    Dim srcDesignTime As CManagedComponentWrapper = source.Instantiate()
    srcDesignTime.ProvideComponentProperties()

    ' Create the destination component.
    Dim destination As IDTSComponentMetaData100 = _
      dataFlowTask.ComponentMetaDataCollection.New()
    destination.ComponentClassID = "DTSAdapter.OleDbDestination"
    Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate()
    destDesignTime.ProvideComponentProperties()


    ' Create the path.
    Dim path As IDTSPath100 = dataFlowTask.PathCollection.New()
    path.AttachPathAndPropagateNotifications(source.OutputCollection(0), _
      destination.InputCollection(0))

  End Sub

End Module
Integration Services 圖示 (小) 掌握 Integration Services 的最新狀態

若要取得 Microsoft 的最新下載、文件、範例和影片以及社群中的選定解決方案,請瀏覽 MSDN 或 TechNet 上的 Integration Services 頁面:

若要得到這些更新的自動通知,請訂閱該頁面上所提供的 RSS 摘要。