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 IDTSPath90 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 IDTSPath90 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 IDTSOutput90 of the upstream component and an IDTSInput90 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 use 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.

Sample

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("DTS.Pipeline.1");
      TaskHost thMainPipe = e as TaskHost;
      MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;

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

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

      // Create the path.
      IDTSPath90 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("DTS.Pipeline.1")
    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 IDTSComponentMetaData90 = _
      dataFlowTask.ComponentMetaDataCollection.New()
    source.ComponentClassID = "DTSAdapter.OleDbSource"
    Dim srcDesignTime As CManagedComponentWrapper = source.Instantiate()
    srcDesignTime.ProvideComponentProperties()

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


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

  End Sub

End Module

Change History

Release History

17. Juli 2006

Changed content:
  • Replaced code examples with longer samples.

Siehe auch

Konzepte

Selecting Input Columns Programmatically

Hilfe und Informationen

Informationsquellen für SQL Server 2005