Solved

xp_cmdshell return code always zero

Posted on 2008-06-10
1
243 Views
Last Modified: 2011-09-20
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?
0
Comment
Question by:johnnyg123
[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
1 Comment
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21753528
use no_output

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

740 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