使用.Net在数据流任务中按下映射 [英] Pressing mappings in the Data Flow Task using .Net
本文介绍了使用.Net在数据流任务中按下映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
几周前我问了这个问题:
"Pressing" the mapping tabs in the Data Flow Task without opening the solution
现在我可以使用以下代码在PowerShell中加载包对象:
Add-Type -Path 'C:WindowsMicrosoft.NETassemblyGAC_MSILMicrosoft.SqlServer.ManagedDTSv4.0_15.0.0.0__89845dcd8080cc91Microsoft.SqlServer.ManagedDTS.dll';
$pkg = "C: est.dtsx";
$app = New-Object -TypeName Microsoft.SqlServer.Dts.Runtime.Application
$app | Get-Member
$Package = $app.LoadPackage($pkg, $null, $FALSE)
$Package | Get-Member
$Package.Executables
$DataFlowTask = $Package.Executables | Where-Object {$_.('Description') -eq ("Data Flow Task")};
我的目标是刷新目标和源的数据流任务中的元数据(映射)。
我想在对象上调用这些方法,我认为这应该会起到作用(参见Link)
instance.AcquireConnections(null);
instance.ReinitializeMetaData();
instance.ReleaseConnections();
但我在上面创建的包对象中找不到数据流对象。包对象中数据流任务的地址是什么?
推荐答案
我不确定如何使用PowerShell完成此操作,但我将提供C#解决方案。
//loop over control flow tasks
foreach (DtsRuntime.Executable tsk in pkg.Executables)
{
DtsRuntime.TaskHost TH = (DtsRuntime.TaskHost)tsk
//Getting the data flow task object
if (TH.InnerObject.ToString() == "System.__ComObject")
{
try
{
DtsWrapper.MainPipe m = (DtsWrapper.MainPipe)TH.InnerObject;
DtsWrapper.IDTSComponentMetaDataCollection100 mdc = m.ComponentMetaDataCollection;
//loop over data flow task components
foreach (DtsWrapper.IDTSComponentMetaData100 md in mdc)
{
//get the OLE DB Destination component
if(md.ComponentClassID == app.PipelineComponentInfos["OLE DB Destination"].CreationName)
{
//add your code here
}
}
}
catch
{
}
}
}
此代码由以下答案改进而来:Reverse engineering SSIS package using C#
我在PowerShell方面没有太多经验,但我会尝试提供一些有用的链接:
- Get-SsisMetadata.ps1
- How to create SSIS package with PowerShell?(此链接包含从PowerShell执行C#脚本的方法-它可能会有所帮助)
这篇关于使用.Net在数据流任务中按下映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文