Link to home
Start Free TrialLog in
Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on

xp_cmdshell return code always zero

I have the following sql server 2003 scheduled job that runs a vb.net 2005 console application

DECLARE @rc int

EXEC @rc =  master.dbo.xp_cmdshell '\\server\incomestatement\shopincomestatement.exe'


IF @rc  = 200
BEGIN
  exec dealer_income_error_send_mail
END

IF  @rc  = 0
BEGIN
 exec dealer_income_success_send_mail
END


I thought I read somewhere that I could force a return code by using the following in my vb.net app

If ISProcess.AppPathError = True Then
                Environment.ExitCode = 100
                Exit Sub
            End If

            If ISProcess.AppConfigError = True Then
                Environment.ExitCode = 200
                Exit Sub
            End If

            If ISProcess.LogFileError = True Then
                Environment.ExitCode = 300
                Exit Sub
            End If

            If ISProcess.ErrorFileError = True Then
                Environment.ExitCode = 400
                Exit Sub
            End If

            If ISProcess.errorflag = False Then
                Environment.ExitCode = 0
            Else
                Environment.ExitCode = 911
            End If



By using debug I see that  the  Environment.ExitCode is being set to 200, however it seems the job is
taking the @rc = 0 path

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial