Is there a way to get an error that is raised from a sql server stored
procedure when executed from a sqlcommand object? thanks!

RE: Get error raised from sql command? by MisbahArefin

MisbahArefin
Thu Mar 06 01:03:01 CST 2008

try RAISEERROR
http://msdn2.microsoft.com/en-us/library/ms177497.aspx

--
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin


"Smokey Grindel" wrote:

> Is there a way to get an error that is raised from a sql server stored
> procedure when executed from a sqlcommand object? thanks!
>
>
>

Re: Get error raised from sql command? by Smokey

Smokey
Thu Mar 06 06:39:32 CST 2008

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

"Misbah Arefin" <MisbahArefin@discussions.microsoft.com> wrote in message
news:CA400CCD-B402-4CEF-9391-0A82CF137DB6@microsoft.com...
> try RAISEERROR
> http://msdn2.microsoft.com/en-us/library/ms177497.aspx
>
> --
> Misbah Arefin
> https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
> http://www.linkedin.com/in/misbaharefin
>
>
> "Smokey Grindel" wrote:
>
>> Is there a way to get an error that is raised from a sql server stored
>> procedure when executed from a sqlcommand object? thanks!
>>
>>
>>



Re: Get error raised from sql command? by Mufaka

Mufaka
Thu Mar 06 11:27:34 CST 2008

Smokey Grindel wrote:
> 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
>
> "Misbah Arefin" <MisbahArefin@discussions.microsoft.com> wrote in message
> news:CA400CCD-B402-4CEF-9391-0A82CF137DB6@microsoft.com...
>> try RAISEERROR
>> http://msdn2.microsoft.com/en-us/library/ms177497.aspx
>>
>> --
>> Misbah Arefin
>> https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
>> http://www.linkedin.com/in/misbaharefin
>>
>>
>> "Smokey Grindel" wrote:
>>
>>> 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.

Re: Get error raised from sql command? by MisbahArefin

MisbahArefin
Thu Mar 06 11:46:04 CST 2008

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
}

--
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin


"Smokey Grindel" wrote:

> 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
>
> "Misbah Arefin" <MisbahArefin@discussions.microsoft.com> wrote in message
> news:CA400CCD-B402-4CEF-9391-0A82CF137DB6@microsoft.com...
> > try RAISEERROR
> > http://msdn2.microsoft.com/en-us/library/ms177497.aspx
> >
> > --
> > Misbah Arefin
> > https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
> > http://www.linkedin.com/in/misbaharefin
> >
> >
> > "Smokey Grindel" wrote:
> >
> >> Is there a way to get an error that is raised from a sql server stored
> >> procedure when executed from a sqlcommand object? thanks!
> >>
> >>
> >>
>
>
>