Solved

xp_cmdshell return code always zero

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Limiting string to two deciamls 18 32
Get String split 5 32
scheduling a stored procedure in azue sql server 3 15
Test a query 23 13
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

708 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

17 Experts available now in Live!

Get 1:1 Help Now