以编程方式连接数据流组件
将组件添加到数据流任务后,连接这些组件以创建表示从源通过转换到目标的数据流的执行树。使用 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
|