[SQL SERVER]透過SP執行ssis2012 package(sync/async mode)

  • 2044
  • 0

[SQL SERVER]透過SP執行ssis2012 package(sync/async mode)

透過SP帶參數執行 SSIS package在SSIS2012我個人認為比以前版本簡單許多,

主要是可以不需要開啟xp_cmdshell來呼叫dtxutl(可嘆目前公司還在使用SSIS2008),

SSIS2012這些資訊、操作…等都存放在SSISDB中,下面我舉個簡單例子。

[SQL SERVER] FileIO操作 使用CLR  改用SSIS來處理

 

拉一個scripts task並顯示執行後內容

image

 

image

image

 

部署SSIS專案

image

 

選擇相對應Server和SSIS catalog

image

 

成功

image

image

 

部署成功後只需簡單4步驟即可透過SP來呼叫相關ssis package

1.取執行ID

2.呼叫catalog.create_execution 建立執行SP

3.呼叫catalog.set_execution_parameter_value設定相關參數

4.呼叫catalog.start_execution 執行package

 

ps:預設採取非同步執行,如果想要使用同步模式的話,

需加入SYNCHRONIZED參數(type=50)

 

 

declare @executid int
exec catalog.create_execution 'mypackage'
,'spsample',N'Test.dtsx'
,null,0,@executid out

exec catalog.set_execution_parameter_value 
@executid,30,'sourcefile',"E:\TDDD\IPZ-382\IPZ-382.wmv"

exec catalog.set_execution_parameter_value 
@executid,30,'targetfile',"F:\IPZ-382.wmv"

exec [SSISDB].[catalog].[set_execution_parameter_value] @executid, 
50, N'SYNCHRONIZED',1 –sync mode

exec catalog.start_execution @executid

image

 

同步模式

image

 

非同步模式

image

 

 

參考

Step by step of executing SSIS 2012 package through stored procedure

Execute a SSIS package in Sync or Async mode from SQL Server 2012

A Stored Procedure to Launch a SQL Agent Job and Wait