Re: How to retrieve stored procedure error code in C#?



By generating error codes, do you mean with the RAISEERROR or PRINT
statement?
You can listen to those with the SqlConnection.InfoMessage event.

SqlConnection connection = new SqlConnection(connectionstring);
connection.InfoMessage += new SqlInfoMessageEventHandler(InfoMessage);
connection.Open();

private static void InfoMessage(object sender, SqlInfoMessageEventArgs args)
{
foreach(SqlError arg in args.Errors) {
Response.Write("Number={0}, Message={1}", arg.Number, arg.Message);
}
}

--
This posting is provided "AS IS", with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
"David Carr" <David_Carr@xxxxxxxxxxxxxxxx> wrote in message
news:%2379YZl5nFHA.3304@xxxxxxxxxxxxxxxxxxxxxxx
> Hi there,
>
> My SQL server 2000 stored procedures are generating different error codes.
> I am able to view these error codes when I run the stored proc in Query
> Analyzer. I am hoping to be able to obtain in my C# web service.
> Specifically, I am using SqlCommand and SqlDataReader objects for
> executing
> the stored procedure.
>
> Is there a simply mechanism/method to call to obtain the return code? I
> have seen some mention of the stored procedure having to stuff it into a
> parameter - I am hoping that I don't have to modify each of my stored
> procs
> to do that.
>
> Thanks in advance,
> David
>
>


.



Relevant Pages

  • Re: How to retrieve stored procedure error code in C#?
    ... To better clarify things for all, my SQL stored proc is given below and ... >> I am able to view these error codes when I run the stored proc in Query ... >> the stored procedure. ...
    (microsoft.public.dotnet.framework.adonet)
  • RAISERROR descriptions
    ... I am connecting Access 2002 to a Microsoft SQL 2000 server. ... When I try to run a stored procedure that returns errors, I can only read the error codes, and not the description of the error. ... On Error Goto HandleError ...
    (microsoft.public.sqlserver.programming)
  • How to retrieve stored procedure error code in C#?
    ... My SQL server 2000 stored procedures are generating different error codes. ... I am able to view these error codes when I run the stored proc in Query ... have seen some mention of the stored procedure having to stuff it into a ...
    (microsoft.public.dotnet.framework.adonet)