在 PowerShell 中组装 SSIS 包

发布于 2024-10-15 12:57:24 字数 1867 浏览 10 评论 0原文

我应该在序言中说,我在 OOP 语言中编写脚本或编程的经验是有限的。

我正在研究一种使用 PowerShell 以编程方式创建和执行 SSIS 包的方法。不幸的是,大多数可用于 PowerShell 和 SSIS 的资源都是用于从 SSIS 调用 PS,而不是相反。

不过,我找到了许多用于 VB/C# 创建 SSIS 包的资源。

此处的示例资源。

我已经通过调用 DTS/SSIS 程序集成功转换了大部分代码,但现在无法将 TaskHost 对象转换为主管道。

示例代码:

[Void][Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.ManagedDTS')
[Void][Reflection.Assembly]::LoadWithPartialName('Microsoft.Sqlserver.DTSPipelineWrap')

# Create the Package and application, set its generic attributes

$Package = New-Object Microsoft.SqlServer.Dts.Runtime.Package
$Package.CreatorName = $CreatorName

$App = New-Object Microsoft.SqlServer.Dts.Runtime.Application

# Set connection info for our package

$SourceConn = $package.Connections.Add("OLEDB")
$SourceConn.Name = "Source Connection"
$SourceConn.set_ConnectionString("Data Source=$SourceServer;Integrated Security=True")

$TargetConn = $package.Connections.Add("OLEDB")
$TargetConn.Name = "Target Connection"
$TargetConn.set_ConnectionString("Data Source=$TargetServer;Integrated Security=True")

# Build the tasks

# Data Flow Task - actually move the table

[Microsoft.SQLServer.DTS.Runtime.Executable]$XferTask = $Package.Executables.Add("STOCK:PipelineTask")

$XferTaskTH = [Microsoft.SqlServer.Dts.Runtime.TaskHost]$XferTask

$XferTaskTH.Name = "DataFlow"
$XferTaskTH.Description = "Dataflow Task Host"

$DataPipe = [Microsoft.SQLServer.DTS.pipeline.Wrapper.MainPipeClass]($XferTaskTH.InnerObject)

一切正常,直到最后一行,当我收到错误时:

无法转换 “System.__ComObject”类型值 “System.__ComObject#{}”到 类型 “Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipeClass”

欢迎任何帮助或想法!

I should preface by saying my experience with scripting or programming in OOP languages is limited.

I'm working on a method for programatically creating and executing SSIS packages using PowerShell. Unfortunately, most of the resources available for PowerShell and SSIS are for calling PS from SSIS, not the other way around.

I have, however, found a number of resources for VB/C# for creating SSIS packages.

Example resource here.

I've succeeded in converting most of the code by calling the DTS/SSIS assemblies, but it's failing now on converting the TaskHost object to a mainpipe.

Sample code:

[Void][Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.ManagedDTS')
[Void][Reflection.Assembly]::LoadWithPartialName('Microsoft.Sqlserver.DTSPipelineWrap')

# Create the Package and application, set its generic attributes

$Package = New-Object Microsoft.SqlServer.Dts.Runtime.Package
$Package.CreatorName = $CreatorName

$App = New-Object Microsoft.SqlServer.Dts.Runtime.Application

# Set connection info for our package

$SourceConn = $package.Connections.Add("OLEDB")
$SourceConn.Name = "Source Connection"
$SourceConn.set_ConnectionString("Data Source=$SourceServer;Integrated Security=True")

$TargetConn = $package.Connections.Add("OLEDB")
$TargetConn.Name = "Target Connection"
$TargetConn.set_ConnectionString("Data Source=$TargetServer;Integrated Security=True")

# Build the tasks

# Data Flow Task - actually move the table

[Microsoft.SQLServer.DTS.Runtime.Executable]$XferTask = $Package.Executables.Add("STOCK:PipelineTask")

$XferTaskTH = [Microsoft.SqlServer.Dts.Runtime.TaskHost]$XferTask

$XferTaskTH.Name = "DataFlow"
$XferTaskTH.Description = "Dataflow Task Host"

$DataPipe = [Microsoft.SQLServer.DTS.pipeline.Wrapper.MainPipeClass]($XferTaskTH.InnerObject)

Everything works fine til the last line, when I get the error:

Cannot convert the
"System.__ComObject" value of type
"System.__ComObject#{}" to
type
"Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipeClass"

Any assistance or ideas are welcome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偏爱你一生 2024-10-22 12:57:24

Microsoft.SqlServer.DTSPipelineWrap 大量使用 COM 实例。

此论坛帖子建议使用 CreateWRapperOfType 方法:
http://social. technet.microsoft.com/Forums/en-US/ITCG/thread/0f493a31-fbf0-46ac-a6a5-8a10af8822cf/

您可以尝试以下操作:

$DataPipe = [System.Runtime.InteropServices.Marshal]::CreateWrapperOfType($XferTaskTH.InnerObject, [Microsoft.SQLServer.DTS.pipeline.Wrapper.MainPipeClass])

不会出错并生成对象 - 我不是确定什么类型。

Microsoft.SqlServer.DTSPipelineWrap makes heavy use of COM instances.

This forum post suggested using CreateWRapperOfType method:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/0f493a31-fbf0-46ac-a6a5-8a10af8822cf/

You could try this:

$DataPipe = [System.Runtime.InteropServices.Marshal]::CreateWrapperOfType($XferTaskTH.InnerObject, [Microsoft.SQLServer.DTS.pipeline.Wrapper.MainPipeClass])

Doesn't error out and produces an object--I'm not sure of what type.

七堇年 2024-10-22 12:57:24

您始终可以将上面引用的工作 .NET 版本编译为 exe,并允许它根据需要接受参数以创建 SSIS 包。然后,使用 Powershell 根据需要使用参数调用可执行文件。

You could always just compile the working .NET version you referenced above into an exe, and allow it to accept parameters as needed in order to create the SSIS packages. Then, use Powershell to call the executable with the parameters as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文