将组件添加到数据流任务后,连接这些组件以创建表示从源通过转换到目标的数据流的执行树。 使用 IDTSPath100 对象连接数据流中的组件。
创建路径
调用 PathCollection 接口的 MainPipe 属性的新方法以创建新路径并将其添加到数据流任务中的路径集合。 此方法返回新的断开连接的 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
有关来自Microsoft的最新下载、文章、示例和视频,以及来自社区的所选解决方案,请访问 MSDN 上的 Integration Services 页面:
访问 MSDN 上的 Integration Services 页
若要获得有关这些更新的自动通知,请订阅该页上提供的 RSS 源。