I need to execute a Data Transformation Services (DTS) package from within a stored procedure but can't find the syntax. How can I execute the package?
Unfortunately, no T-SQL command lets you run a DTS package, so you have to jump through some hoops to address your problem. You can choose from three possible solutions; your specific needs will determine which solution is best.
Solution 1You can use the dtsrun command-line utility to invoke DTS packages. Dtsrun isn't a T-SQL command, but you can invoke command-line utilities by using the xp_cmdshell extended stored procedure. Xp_cmdshell executes a given command string as an OS command shell and returns any output as rows of text. This means that your stored procedure could call xp_cmdshell, which invokes dtsrun, which in turn invokes your package.
Solution 2You can schedule a DTS package as a job that the SQL Server Agent job-management service executes. You can use the sp_start_job procedure in msdb to create an on-demand job that runs the package. The SQL Server Agent simply runs the DTS package by executing an Operating System Command task that runs the command-line utility dtsrun that I describe in Solution 1. However, multiple users can't run the same job at the same time. Users will receive an error message if they try to start a job that's already running. Therefore, this solution isn't a good choice unless users can access the DTS job one at a time.
Solution 3DTS packages are technically nothing more than COM objects, and you can easily manipulate them through the usual COM interfaces. You can write a COM wrapper program that calls and manipulates the DTS package any way you want. You can then call this wrapper from T-SQL by using the sp_OACreate() function that lets T-SQL create and manipulate an instance of a COM object on your SQL Server. This option is the most difficult to implement, but it can provide additional flexibility that you won't find in Solution 1 or Solution 2.
If you don't have a username & password, please
register now.
Reader Comments
Excellent! Thank you.
Carl Urbina- May 14, 2004
Simple, to the point and very helpful! Thanks!
Anonymous User- January 21, 2005
Article Rating 5 out of 5
Short and sweet. Really Nice, To the point
Anonymous User- January 31, 2005
Article Rating 5 out of 5
Just what I needed to know. Very usefull. Tks.
Anonymous User- March 04, 2005
Article Rating 5 out of 5
Just what I needed to know. Very usefull. Tks.
Anonymous User- March 04, 2005
Article Rating 5 out of 5
Code examaples are useful in this type of article...
Anonymous User- April 04, 2005
Article Rating 3 out of 5
Very good! This article saved me a lot of research through SQL documentation
Anonymous User- June 09, 2005
Article Rating 4 out of 5
Very interesting but any samples/syntax on how to do it?? I'm new to SQL. Thanks!
Anonymous User- June 24, 2005
Article Rating 4 out of 5
Not Usefull! Where's the example... Its pretty easy to add a short example of Solution listed... That's why i dont come here very often - qand wont ever renew... R Lewis - MCSD