• subscribe
November 20, 2001 12:00 AM

Executing a DTS Package in a Stored Procedure

SQL Server Pro
InstantDoc ID #23012

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 1—You 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 2—You 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 3—DTS 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.


ARTICLE TOOLS

Comments
  • Robert
    5 years ago
    Jan 18, 2007

    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

  • Anonymous User
    7 years ago
    Jun 24, 2005

    Very interesting but any samples/syntax on how to do it?? I'm new to SQL. Thanks!

  • Anonymous User
    7 years ago
    Jun 09, 2005

    Very good! This article saved me a lot of research through SQL documentation

  • Anonymous User
    7 years ago
    Apr 04, 2005

    Code examaples are useful in this type of article...

  • Anonymous User
    7 years ago
    Mar 04, 2005

    Just what I needed to know. Very usefull. Tks.

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...