johnnyg123
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\ shopincome statement. exe'
IF @rc = 200
BEGIN
exec dealer_income_error_send_m ail
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?
DECLARE @rc int
EXEC @rc = master.dbo.xp_cmdshell '\\server\incomestatement\
IF @rc = 200
BEGIN
exec dealer_income_error_send_m
END
IF @rc = 0
BEGIN
exec dealer_income_success_send
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.