我最近一直在尝试从.NET代码创建SSIS包,而不是在Visual Studio中使用拖放。作为包文档的一部分,我希望能够注释数据流路径。
下面的代码-复制自MSDN -在两个SSIS数据流组件之间建立了一条路径。通过添加
path.Name = "My name";
new Application().SaveToSqlServer(package, null, "localhost", "myUser", "myPassword");我可以将路径名称设置为任何我喜欢的名称,然后将包保存在本地SQL Server中。但是,当我在Visual Studio2008中打开该包时,只能在path属性下看到路径的名称。
在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]);
}
}发布于 2010-10-06 21:14:29
我成功地在不同的论坛上得到了答案。请参阅
http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/23e6a43f-911f-44da-8e69-cd9e53d7e5ed
https://stackoverflow.com/questions/3803774
复制相似问题