Technical Article

xp_cmdshell error return value

,

The error checking seems to work better than the @@error after exiting out of a xp_cmdshell DOS task concerning a failed or successfull attempt.

--@backupfile is just the file name being used
DECLARE @cmdstr2 nvarchar(4000),@retval2 int
 
SET @cmdstr= 'copy /Y '+@BackupFile+ 'f:\db_dump\db_name\'
      EXEC @retval2 = master..xp_cmdshell @cmdstr
IF (@retval2 = 0)
  BEGIN
Print 'The   file '+@BackupFile+ ' was moved to f:\db_dump\db_name\ successfully.'
  END
ELSE
BEGIN 
--Page Block goes here to page the DBA....
Print ' The Move failed contact The Red Ranger'

Return
END

Rate

(1)

You rated this post out of 5. Change rating

Share

Share

Rate

(1)

You rated this post out of 5. Change rating