Connecting Data Flow Components Programmatically

After you have added components to the data flow task, you connect them to create an execution tree that represents the flow of data from sources through transformations to destinations. You use IDTSPath100 objects to connect the components in the data flow.

Creating a Path

Call the New method of the PathCollection property of the MainPipe interface to create a new path and add it to the collection of paths in the data flow task. This method returns a new, disconnected IDTSPath100 object, which you then use to connect two components.

Call the AttachPathAndPropagateNotifications method to connect the path and to notify the components participating in the path that they have been connected. This method accepts an IDTSOutput100 of the upstream component and an IDTSInput100 of the downstream component as parameters. By default, the call to the component's ProvideComponentProperties method creates a single input for components that have inputs, and a single output for components that have outputs. The following example uses this default output of the source and input of the destination.

Next Step

After you establish a path between two components, the next step is to map input columns in the downstream component, which is discussed in the next topic, Selecting Input Columns Programmatically.


The following code sample shows how to establish a path between two components.

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 =
      source.ComponentClassID = "DTSAdapter.OleDbSource";
      CManagedComponentWrapper srcDesignTime = source.Instantiate();

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

      // Create the path.
      IDTSPath100 path = dataFlowTask.PathCollection.New();


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 = _
    source.ComponentClassID = "DTSAdapter.OleDbSource"
    Dim srcDesignTime As CManagedComponentWrapper = source.Instantiate()

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

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

  End Sub

End Module
Integration Services icon (small) Stay Up to Date with Integration Services

For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN or TechNet:

For automatic notification of these updates, subscribe to the RSS feeds available on the page.