SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Run SSIS packages from remote client with stored procedure

By Jason Rowland,

Recently I needed to run SSIS packages from application servers that didn't have SSIS or BIDS installed on them. The application initiating the SSIS package also couldn't wait for the package to finish running before returning. After a few searches on the Internet I found a handful of ways to run SSIS packages remotely, but I wasn't satisfied with any of them, and that's when I came up with my own solution. I created a stored procedure on the SQL Server where SSIS is running that accepts a parameter containing the switches that would be used in the dtexec.exe utility. An example of the stored procedure being executed would look like this:

exec dbo.spRunSSISPackage '/SQL "\SSISBrokerTestImport" /SERVER "SQL1" /CONNECTION ImportFile;"C:\SSISBrokerTest\tblImportFiles.csv"'

At this point it looks pretty basic, but there is a little bit of complexity under the hood of this proc. This procedure doesn't actually run the SSIS package; it puts it in a service broker queue. By doing this, the program making the stored procedure call is able to continue without having to wait for the SSIS package to complete. Then, when the message is picked up from the queue it is processed and the dtexec.exe utility is executed using xp_cmdshell passing the parameter value from the initial stored procedure call.

I have attached 3 files to this article that you can use to test this out. To get everything staged, download all 3 files and take the following steps:

  1. Save the tblImportFiles.csv file to a folder that your SQL Server can access. I have a virtual SQL Server named SQL1 and I put it on the C: drive of SQL1 in a folder called SSISBrokerTest. This file will be imported into a table called tblImportFiles in the SSISBrokerTestDB database.
  2. Unzip SSISBrokerTestDB_ImportFiles.zip and open the SSISBrokerTestDB_ImportFiles solution to deploy the SSISBrokerTestImport.dtsx package to your SQL Server. Mine is deployed to SQL1.
  3. Open the SSISBroker.sql file connecting to the same server where the SSIS package was deployed.
  4. In the SSISBroker.sql file, find the string --EXEC sp_xp_cmdshell_proxy_account 'Domain\User', 'yourPassword'; and replace the parameter values with an account and password that can execute xp_cmdshell and run the script. Examine this sql script file closely as it contains the mechanics of the process.

Now that everything is staged open up a new query window in SSMS and run the following code. Be sure to replace SQL1 with the name of your SQL Server, the path to the tblImportFiles.csv to the path where you saved it and the path to the SSIS package where yours is saved.

Use SSISBrokerTestDB;
go declare @x varchar(8000); set @x = '/SQL "\SSISBrokerTestImport" /SERVER SQL1 /CONNECTION ImportFile;"C:\SSISBrokerTest\tblImportFiles.csv" /CONNECTION SQL1;"\"Data Source=SQL1;Initial Catalog=SSISBrokerTestDB;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;\""' exec spRunSSISPackage @x

After the package has a moment to complete run this query:

select * from dbo.tblImportFiles

If your query returns these results you have successfully run an SSIS package with a stored procedure call.



tblImportFiles.csv | SSISBroker.sql | SSISBrokerTestDB_ImportFiles.zip
Total article views: 8173 | Views in the last 30 days: 3
Related Articles

Execute SSIS package stored in Database - From Stored Procedure

Execute SSIS package stored in Database - From Stored Procedure


How to execute ssis package through stored procedure

How to execute ssis package through stored procedure


Call a DTSX or SSIS Package from a Stored Procedure

Call a DTSX or SSIS Package from a Stored Procedure


Temporary Stored Procedures

Temporary Stored Procedures - little known sql server feature