Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Execute DTS package from stored procedure

Posted on 2004-08-16
14
Medium Priority
?
517 Views
Last Modified: 2013-11-30
I tried to execute a DTS package from a stored procedure. Here is my code

CREATE PROCEDURE [RunDTS] AS
exec master..xp_cmdshell 'dtsrun /S COCHISE5 /U vnguyen/P sqlserver/ N DTS_Outbox'

it  seems correct to me but when I execute the stored procedure from Query Analyzer, I received an error output
output                                                                                                                                                                                                                                                          
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DTSRun:  Must specify a package name or guid or version guid, or a source filename.

DTSRun:  Invalid command options

Usage:  dtsrun /option [value] [/option [value]] ...

Options ('/?' shows this screen; '-' May be substituted for '/'):



  Package retrieval:
.....

Please help. Thanks. Van Nguyen

0
Comment
Question by:CochiseCounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +2
14 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 11814074
have you tried to put a space between sqlserver and /N ?
0
 
LVL 34

Expert Comment

by:arbert
ID: 11814092
Actually, that whole string is a little off:


'dtsrun /S COCHISE5 /U vnguyen /P sqlserver /N DTS_Outbox'
0
 

Author Comment

by:CochiseCounty
ID: 11814174
Thanks arbert, seems like it is working with the code, but now the problem I have is the security/permission, this is what I got...

Error string:  Error opening datafile: Access is denied.

Please help
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 17

Expert Comment

by:BillAn1
ID: 11814183
Only thing that looks out of place is your spaces - there should be a space between each value and the next /, and no space to the letter i.e.

CREATE PROCEDURE [RunDTS] AS
exec master..xp_cmdshell 'dtsrun /S COCHISE5 /U vnguyen  /P sqlserver  /N DTS_Outbox'

assuming you have such a DTS package called DTS_Outbox
0
 

Author Comment

by:CochiseCounty
ID: 11814265
Of course I have the DTS package called DTS_Outbox. That package is used to copy data from a SQL table to a text file. I am not sure how to set permission for that text file, the text file is not on the web server.
0
 
LVL 34

Expert Comment

by:arbert
ID: 11814310
Did you use a drive letter in your DTS package for the filename?  You should use UNC paths to the file.  Also, like BillAn1 suggested, you need to make sure you have right to the file (wherever it is).  If it's on a different server, you need to make sure the user/password you use has access to that other server.  Also, if you end up scheduling this DTS package, you need to make sure the SQLAgent account has rights to the files/resources too.

Brett
0
 
LVL 9

Expert Comment

by:SoftEng007
ID: 11814316
verify your server COCHISE5 has permissions to the files your working with.
0
 
LVL 9

Expert Comment

by:SoftEng007
ID: 11814332
wow arbert you write faster than I can think !
0
 
LVL 34

Expert Comment

by:arbert
ID: 11814359
lol....No, I type faster than I think (gets me in trouble all the time)!!!  I think most people think faster than I type and think :)
0
 

Author Comment

by:CochiseCounty
ID: 11814411
If there is something wrong with the permission, how come when I right click the package and Execute, it works fine. Thanks again
0
 
LVL 12

Expert Comment

by:kselvia
ID: 11816082
You can also start a DTS package from T-SQL using sp_oacreate without using xp_cmdshell;

DECLARE @hr INT
DECLARE @oPKG INT
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUT
IF @hr = 0
     EXEC @hr = sp_OAMethod @oPKG, 'LoadFromSQLServer("(local)", "", "", 256, , , , "DTS_Outbox'")', NULL
IF @hr = 0
     EXEC @hr = sp_OAMethod @oPKG, 'Execute'
IF @hr = 0
     EXEC @hr = sp_OADestroy @oPKG
0
 
LVL 9

Expert Comment

by:SoftEng007
ID: 11817051
>>If there is something wrong with the permission, how come when I right click the package and Execute, it works fine. Thanks again

in DTS designer you're running the package on the machine that DTS designer is running on. when you call the package using dtsrun /S tell dts to run the package located on /server. the drive or folder permissions may not be the same from machine to machine. I would log in to the machine in question as the user that will run the package and try to open the file.
0
 

Author Comment

by:CochiseCounty
ID: 11821470
Hi kselvia, I tried to use the code that you gave me. My DTS package is to copy data from SQL table to a text file. WHen I execute the stored procedure from Query analyzer, it says 'The command(s) completed successfully.'. But there is no text file created. So what did I do wrong?
0
 
LVL 12

Accepted Solution

by:
kselvia earned 1000 total points
ID: 11821856
Try this, it should print an error message for you

DECLARE @object INT
DECLARE @src INT
DECLARE @desc VARCHAR(1000)
DECLARE @hr INT
DECLARE @oPKG INT
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUT
IF @hr = 0
     EXEC @hr = sp_OAMethod @oPKG, 'LoadFromSQLServer("(local)", "", "", 256, , , , "DTS_Outbox")', NULL
ELSE
begin
     EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
     Print @desc
     RETURN
end

IF @hr = 0
     EXEC @hr = sp_OAMethod @oPKG, 'Execute'
ELSE
begin
     EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
     Print @desc
     RETURN
end

IF @hr = 0
     EXEC @hr = sp_OADestroy @oPKG
ELSE
begin
     EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
     Print @desc
     RETURN
end
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question