2011-02-02 98 views
8

我應該說我的腳本編程或面向對象編程語言的經驗是有限的。在PowerShell中組裝SSIS包

我正在研究使用PowerShell以編程方式創建和執行SSIS包的方法。不幸的是,PowerShell和SSIS可用的大部分資源都是從SSIS調用PS,而不是其他方式。

但是,我已經找到了許多用於創建SSIS包的VB/C#的資源​​。

Example resource here.

我已經成功地通過調用DTS/SSIS組件轉換大部分的代碼,但它現在沒有在TaskHost對象轉換爲mainpipe。

示例代碼:

[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) 

一切正常,直到最後一行,當我得到的錯誤:

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

任何幫助或想法,歡迎!

+1

我是upvoting這個老問題,因爲我不明白爲什麼它downvotes =/ – jadarnel27 2011-11-04 12:54:57

+2

@ jadarnel27 - 他們主要是報復downvotes。我惹惱了一些人,他們低估了我所問過的幾個問題(因爲它可以自由下調問題)。我很欣賞你的公平感。 – JNK 2011-11-04 13:15:25

回答

1

您可以隨時將上面引用的工作.NET版本編譯爲exe文件,並允許它根據需要接受參數以創建SSIS包。然後,使用Powershell根據需要使用參數調用可執行文件。

+0

爲安全起見,我們假設它需要是一個自包含的將從SQL Server執行的powershell腳本。 – JNK 2011-02-02 19:19:24