
Signature
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin
I think you misunderstood me... I already am raising errors in the stored
proc's... I want to know how I can find out what the error was when I ran it
inside of ADO.NET so I can respond to the error in my program
> try RAISEERROR
> http://msdn2.microsoft.com/en-us/library/ms177497.aspx
>
>> Is there a way to get an error that is raised from a sql server stored
>> procedure when executed from a sqlcommand object? thanks!
Mufaka - 06 Mar 2008 17:27 GMT
> I think you misunderstood me... I already am raising errors in the stored
> proc's... I want to know how I can find out what the error was when I ran it
[quoted text clipped - 5 lines]
>>> Is there a way to get an error that is raised from a sql server stored
>>> procedure when executed from a sqlcommand object? thanks!
What severity are you using in your raiserror? The following causes a
System.Data.SqlClient.SqlException to be raised in the client:
raiserror('Error Message', 17, 1)
return
The exceptions message property is "Error Message" in this case.
Misbah Arefin - 06 Mar 2008 17:46 GMT
try this in your stored proc
RAISEERROR(N'This is a message %s %d', -- message text
16, --severity
1, --state
N'number', --first argument
5); --second argument
and in your code you can get this error message in the SqlException object
try
{
ExecuteSP();
}
catch(SqlException ex)
{
Console.WriteLine(ex); //ex.Message will have the message text you used in
raiseerror
}

Signature
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin
> I think you misunderstood me... I already am raising errors in the stored
> proc's... I want to know how I can find out what the error was when I ran it
[quoted text clipped - 5 lines]
> >> Is there a way to get an error that is raised from a sql server stored
> >> procedure when executed from a sqlcommand object? thanks!