Solved

xp_cmdshell return code always zero

Posted on 2008-06-10
1
238 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

839 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