Link to home
Start Free TrialLog in
Avatar of Paula-at-APEX
Paula-at-APEX

asked on

Calling SSIS from a Stored Procedure

I have a 32 bit SSIS package that I need to call from a stored procedure in MS SQL. I need to call the 32 bit version of DTExec.exe. But I am having pathing issues using the xp_cmdshell. I have also tried it without the double quotes.

The error I am getting with this code is: 'C:\Program' is not recognized as an internal or external command,

-- code --
DECLARE @ReturnCode int
DECLARE @SqlQuery nvarchar(2000)

set @SqlQuery = '"C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\DTExec.exe" /SQL "pkgAbraTransferSpreadsheet" '
print '*' + @sqlQuery + '*'
EXEC @ReturnCode = master..xp_cmdshell @SqlQuery
 
print 'return code: ' + convert(nvarchar(15),@returncode)
Avatar of ProjectChampion
ProjectChampion
Flag of United Kingdom of Great Britain and Northern Ireland image

I'd suggest instead of using XP_CMDShell which entails unnecessary security risks and may as well be disabled on your production servers, create a SQL Server job that runs the pertinent SSIS package, setup all the necessary parameters and other settings (including the option to run the package in 32 bit mode) and the call sp_start_job inside your proc to start the job.

Also I appreciate that you may have a special but valid scenario to have to run an SSIS package from within a proc, but for multiple reasons it's not usually best practice for instance, since the package will run outside the stored proc context, there's no easy/reliable way to ensure it's done its job successfully or as that matters even if it's finished or still running. So it's usually the other way round, i.e. you call the procs from within a package.

Good luck anyways.  : )
ASKER CERTIFIED SOLUTION
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paula-at-APEX
Paula-at-APEX

ASKER

WOW. Would have never figured that out. It worked great. Thanks.