dbTalk Databases Forums  

How to trap xp_cmdshell dtsrun error messages

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss How to trap xp_cmdshell dtsrun error messages in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Admin
 
Posts: n/a

Default How to trap xp_cmdshell dtsrun error messages - 06-11-2004 , 02:01 PM






Hi Here is my store procedure. The below code is not giving error at all when dts fails.

Can any one please help me how to trap xp_cmdshell dtsrun error message

CREATE PROCEDURE [dbo].[usp_VRSURVEYComments] A
exec USP_ReadVRUDirector
set nocount on
DECLARE @filename Char(20),@cmdstring varchar(150) ,@Error int
DECLARE VRUCFileListCursor CURSOR Fast_FORWARD FO
SELECT filelist FROM TBLVRUDir where filelist like 'V%.CMM' order by filelis
OPEN VRUCFileListCurso
FETCH NEXT FROM VRUCFileListCurso
INTO @filename
WHILE @@FETCH_STATUS =
BEGIN
truncate table VRUSURVEYComment

set @cmdstring = 'copy e:\ftproot\vru\'+@filename +' e:\ftproot\vru\VRUComments.txt
exec master..xp_cmdshell @cmdstrin

exec master..xp_cmdshell 'dtsrun /S WPCCP005DS /E /N VRUSurveyComments'


SELECT @Error = @@ERRO

IF @Error <>
BEGI
Print @Erro
EN


UPDATE VRUSURVEYComments SET [Filename] = @filename -- where [Filename] is nul

update VRUSURVEYComments set cur= 'T'
exec master..xp_cmdshell 'dtsrun /S WPCCP005DS /E /N VRUSurveyCommentsExport
FETCH NEXT FROM VRUCFileListCurso

INTO @filenam
EN
CLOSE VRUCFileListCurso
DEALLOCATE VRUCFileListCurso




Reply With Quote
  #2  
Old   
John Bell
 
Posts: n/a

Default Re: How to trap xp_cmdshell dtsrun error messages - 06-14-2004 , 10:54 AM






Hi

Rather than using xp_cmdshell to rename the file try using something like
the following to change the name of the source file. Using the FSO you can
check errors more easily!

http://www.sqldts.com/default.aspx?200
http://www.sqldts.com/default.aspx?246

You should also check the return value from xp_cmdshell e.g

DECLARE @cmd sysname, @var sysname, @stat int
SET @var = 'Hello world'
SET @cmd = 'echo ' + @var + ' > G:\var_out.txt'
EXEC @stat = master..xp_cmdshell @cmd
PRINT '@stat= ' + CONVERT(varchar,@stat)

John

"Admin" <admin (AT) emoneylinks (DOT) com> wrote

Quote:
Hi Here is my store procedure. The below code is not giving error at all
when dts fails.

Can any one please help me how to trap xp_cmdshell dtsrun error messages

CREATE PROCEDURE [dbo].[usp_VRSURVEYComments] AS
exec USP_ReadVRUDirectory
set nocount on
DECLARE @filename Char(20),@cmdstring varchar(150) ,@Error int
DECLARE VRUCFileListCursor CURSOR Fast_FORWARD FOR
SELECT filelist FROM TBLVRUDir where filelist like 'V%.CMM' order by
filelist
OPEN VRUCFileListCursor
FETCH NEXT FROM VRUCFileListCursor
INTO @filename
WHILE @@FETCH_STATUS = 0
BEGIN
truncate table VRUSURVEYComments

set @cmdstring = 'copy e:\ftproot\vru\'+@filename +'
e:\ftproot\vru\VRUComments.txt'
exec master..xp_cmdshell @cmdstring

exec master..xp_cmdshell 'dtsrun /S
WPCCP005DS /E /N VRUSurveyComments'


SELECT @Error = @@ERROR

IF @Error <> 0
BEGIN
Print @Error
END


UPDATE VRUSURVEYComments SET [Filename] = @filename --
where [Filename] is null

update VRUSURVEYComments set cur= 'T'
exec master..xp_cmdshell 'dtsrun /S WPCCP005DS /E /N
VRUSurveyCommentsExport'
FETCH NEXT FROM VRUCFileListCursor

INTO @filename
END
CLOSE VRUCFileListCursor
DEALLOCATE VRUCFileListCursor







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.