【发布时间】:2010-09-27 12:34:03
【问题描述】:
我最近一直在尝试从 .NET 代码创建 SSIS 包,而不是在 Visual Studio 中使用拖放。作为包文档的一部分,我希望能够注释数据流路径。
下面的代码 - 复制自 MSDN - 在两个 SSIS 数据流组件之间建立了一条路径。通过添加
path.Name = "My name";
new Application().SaveToSqlServer(package, null, "localhost", "myUser", "myPassword");
我可以将路径名称设置为我喜欢的任何名称,然后将包保存在我的本地 SQL Server 中。但是,当我在 Visual Studio 2008 中打开包时,路径的名称只能在路径属性下看到。
在 Visual Studio 中,还有另一个路径属性 PathAnnotation,其值为 AsNeeded 和其他可能性 SourceName、PathName、Never。将值更改为 PathName 为我提供了我想要的:路径名称显示在 Visual Studio 中数据流选项卡中的路径旁边。
我的问题是:是否可以从代码中设置 PathAnnotation 属性的值?
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]);
}
}
【问题讨论】:
标签: sql-server ssis