Solved

xp_cmdshell return code always zero

Posted on 2008-06-10
1
235 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now