earngreen
asked on
Execute SSIS package from Stored Procedure
I am trying to execute a stored procedure from SSIS and having a probleme with the path. The space between the mssql and (x86) is the culprit. I have attempted to format differently but with no success. Can someone tell me how to format the following to make this work?
SELECT @Path = 'c:\mssql (x86)\90\dts\binn\DTexec.e xe'
SELECT @PackageName = '\package.dtsx'
SELECT @SQLServer = 'srv001'
SELECT @DB = 'db1'
SELECT @StartDate = '''' + '2012/09/06'+ ''',''' + 'yyyy/mm/dd'+ ''''
SELECT @EndDate = '''' + '2012/09/07'+ ''',''' + 'yyyy/mm/dd'+ ''''
SELECT @Cmd = '"' + @Path + '"' + ' /SQ ' + '"' + @PackageName + '"' + ' /SER srv01'
+ ' /SET ' + '"' + '\Package.Variables[user:: @StartDate ].Properti es[Value]' + '"' + ';' + '"' + @StartDate + '"'
+ ' /SET ' + '"' + '\Package.Variables[User:: EndDate].P roperties[ Value]' + '"' + ';' + '"' + @EndDate + '"'
EXEC @ReturnCode = xp_cmdshell @Cmd
SELECT @Path = 'c:\mssql (x86)\90\dts\binn\DTexec.e
SELECT @PackageName = '\package.dtsx'
SELECT @SQLServer = 'srv001'
SELECT @DB = 'db1'
SELECT @StartDate = '''' + '2012/09/06'+ ''',''' + 'yyyy/mm/dd'+ ''''
SELECT @EndDate = '''' + '2012/09/07'+ ''',''' + 'yyyy/mm/dd'+ ''''
SELECT @Cmd = '"' + @Path + '"' + ' /SQ ' + '"' + @PackageName + '"' + ' /SER srv01'
+ ' /SET ' + '"' + '\Package.Variables[user::
+ ' /SET ' + '"' + '\Package.Variables[User::
EXEC @ReturnCode = xp_cmdshell @Cmd
SELECT @Path = '|c:\mssql (x86)\90\dts\binn\DTexec.e xe|'
Here replace | with double quotes ("). Don't use single quote twice :D
Here replace | with double quotes ("). Don't use single quote twice :D
Have you tried to execute this without the full path to dtexec?
and a hat-tip to http://www.codeproject.com/Articles/27156/How-to-Call-SSIS-Package-from-the-Stored-Procedure
SELECT @Path = 'DTexec'
SELECT @PackageName = 'package.dtsx'
SELECT @SQLServer = 'srv001'
SELECT @DB = 'db1'
SELECT @StartDate = '''' + '2012/09/06'+ ''',''' + 'yyyy/mm/dd'+ ''''
SELECT @EndDate = '''' + '2012/09/07'+ ''',''' + 'yyyy/mm/dd'+ ''''
SELECT @Cmd = @Path + ' /SQ ' + @PackageName + ' /SER srv01'
+ ' /SET ' + '\Package.Variables[user::@StartDate].Properties[Value]' + ';' + '"' + @StartDate + '"'
+ ' /SET ' + '\Package.Variables[User::EndDate].Properties[Value]' + ';' + '"' + @EndDate + '"'
--print @cmd
EXEC @ReturnCode = xp_cmdshell @Cmd
and a hat-tip to http://www.codeproject.com/Articles/27156/How-to-Call-SSIS-Package-from-the-Stored-Procedure
ASKER
jared_s, that works but the problem is that it runs under default 64 bit and I need to run 32 bit. If I run 64 bit there are more errors.
ASKER
robert_schutt, Not sure what you mean could you post example.
On my system, if I create a directory "C:\MSSQL (x86)" I can access that through the 'old' name "C:\MSSQL(~1" so you could try changing your first line to:
SELECT @Path = 'c:\MSSQL(~1\90\dts\binn\DTexec.exe'
Then you shouldn't need quotes around it.
ASKER
robert_schutt, sorry this still has an error on my system.
did you check if the name is right with
DIR /X C:\
ASKER
I am certain that the directory is correct. When I run the results of my original query from SQL or from an SQL job it works perfectly. Just not sure why I am having trouble with this syntax.
What I posted so far was purely based on your remark "The space between the mssql and (x86) is the culprit". The notation with ~ is an alternative for the same directory without the space. But on your system the exact name may be different, that's why I suggested checking it with "DIR /X", not to suggest that you don't know where the program is installed ;-)
One other thing that seems odd to me (but I don't know much about the workings of that exe) is the different syntax (specifically the @) between '\Package.Variables[user:: @StartDate ].Properti es[Value]' and'\Package.Variables[Use r::EndDate ].Properti es[Value]' , could it be a copy/paste error?
One other thing that seems odd to me (but I don't know much about the workings of that exe) is the different syntax (specifically the @) between '\Package.Variables[user::
ASKER
I resolved the @ symbol and removed it that was incorrect. Will run your command line to check?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you even tried my suggestion above with ID 38406695?. It was infact the same thing.nfact the same thing.
https://www.experts-exchange.com/questions/27867810/Execute-SSIS-package-from-Stored-Procedure.html?anchorAnswerId=38406695#a38406695
https://www.experts-exchange.com/questions/27867810/Execute-SSIS-package-from-Stored-Procedure.html?anchorAnswerId=38406695#a38406695
ASKER
After trying many things finally got it to work.
1) put the path in your global PATH variable so you can leave it out in the call
2) use the DOS 8.3 name for the directory, it's probably "MSSQL(~1", you can check that in a cmd prompt with:
Open in new window