问题
How to call .dtsx package file which has input parameters from a stored procedure?
Stored Procedure # 1 -> Will pass the list of files to be exported to excel as a Comma Separated value in a variable.
Input variable will be passed to the SSIS Package to export the data to excel.
How to handle the SSIS Package which has Input parameters from a Stored Procedure call?
回答1:
Using DtExec and xp_cmdshell
One way to do that is to run DtExec utility from file system using xp_cmdshell utility inside sql server.
First you have to enable the xp_cmdshell
utility:
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
-- WITH OVERRIDE disables the configuration value checking if the value is valid
RECONFIGURE WITH OVERRIDE
GO
-- To enable the xp_cmdshell component.
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE WITH OVERRIDE
GO
-- Revert back the advance option
EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE WITH OVERRIDE
GO
Then you can use the following command to execute the package and pass avariable value as parameter:
DECLARE @SQLQuery AS VARCHAR(2000)
DECLARE @ServerName VARCHAR(200) = 'ARSHAD-LAPPY'
SET @SQLQuery = 'DTExec /FILE ^"E:\DataTransfer.dtsx^" '
SET @SQLQuery = @SQLQuery + ' /SET \Package.Variables[ServerName].Value;^"'+ @ServerName + '^"'
EXEC master..xp_cmdshell @SQLQuery
GO
References
- Executing a SSIS Package from Stored Procedure in SQL Server
- Run an SSIS package from the command prompt with DTExec.exe
- DTEXEC Command Line Parameters Using Command Files
- dtexec Utility
Helpful links
- How to Call SSIS Package from the Stored Procedure
- Run an SSIS package from SSMS with Transact-SQL (if using SSISDB)
- How To Execute an Integration Services (SSIS) Package from a SQL Server Stored Procedure (if using SSISDB)
来源:https://stackoverflow.com/questions/54893713/how-to-call-dtsx-file-which-has-input-parameters-from-a-stored-procedure