<p>I need to run a stored procedure from a C# application.</p>

<p>I use the following code to do so:</p>

<pre><code>Process sqlcmdCall = new Process();
sqlcmdCall.StartInfo.FileName = "sqlcmd.exe";
sqlcmdCall.StartInfo.Arguments = "-S localhost\\SQLEXPRESS -d some_db -Q \":EXIT(sp_test)\""
sqlcmdCall.Start();
sqlcmdCall.WaitForExit();
</code></pre>

<p>From the sqlcmdCall object after the call completes, I currently get an ExitCode of -100 for success and of 1 for failure (i.e. missing parameter, stored proc does not exist, etc...).</p>

<p>How can I customize these return codes?</p>

<p>H.</p>

If you are trying to call a stored procedure from c# you would want to use ADO.Net instead of the calling sqlcmd via the command line.  Look at
```
SqlConnection
```
and
```
SqlCommand
```
in the
```
System.Data.SqlClient
```
namespace.
Once you are calling the stored procedure via
```
SqlCommand
```
you will be able to catch an exception raised by the stored procedure as well we reading the return value of the procedure if you need to.