Author |
Topic |
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2005-04-15 : 17:36:38
|
how to capture error thrown by RAISEERROR in my stored procedure in asp.net application? I would like to set lable text based on error return by my raiserror?I would appreciate if possible..an example showing this.. |
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2005-04-18 : 12:03:07
|
OK use output parameter..return a string and you that to set you label text...I am sure there should be a way to use RAISEERROR? Mike, Jon, Anyone..? huh.. |
 |
|
jhermiz
3564 Posts |
Posted - 2005-04-18 : 13:15:42
|
One option is to use what you have stated a RETURN PARAMETER in your Stored procedure.This could be some sort of integer which you can CASE out to display specific errors / statuses:1= Good2= Bad3= Erroretc... Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
jhermiz
3564 Posts |
Posted - 2005-04-18 : 13:36:48
|
Don't forget you can return @@Error in your sproc, but either way you will still have to handle the result back into the front end. Why cant you display the error in SQL ? You can customize the message by CASING that error out.Jon Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-04-18 : 15:23:59
|
InfoMessage event of Connection/Command object. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-04-18 : 15:27:41
|
In pure VB it looks like (and doesn't work properly...):Option ExplicitPrivate WithEvents cn As ADODB.Connection... ... ...Private Sub cn_InfoMessage(ByVal pError As ADODB.Error, _adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)MsgBox pError.DescriptionEnd Sub |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-04-18 : 15:34:30
|
And of course you mean RAISERROR ... WITH NOWAIT??? |
 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-04-18 : 16:42:07
|
quote: Originally posted by jhermiz One option is to use what you have stated a RETURN PARAMETER in your Stored procedure.This could be some sort of integer which you can CASE out to display specific errors / statuses:1= Good2= Bad3= Erroretc...
Absolutely, positively, don't do that.SQL Server can, and will override that depending on the error.Sooooo if you code for those values, you may be unpleasantly suprised....Use an ouput variable, and what stoad said.Brett8-) |
 |
|
jhermiz
3564 Posts |
Posted - 2005-04-19 : 10:42:10
|
quote: Originally posted by X002548
quote: Originally posted by jhermiz One option is to use what you have stated a RETURN PARAMETER in your Stored procedure.This could be some sort of integer which you can CASE out to display specific errors / statuses:1= Good2= Bad3= Erroretc...
Absolutely, positively, don't do that.SQL Server can, and will override that depending on the error.Sooooo if you code for those values, you may be unpleasantly suprised....Use an ouput variable, and what stoad said.Brett8-)
Brett you must be reading this incorrectly. I have stated to use a return parameter and 1=Good, 2=bad..was meant to be on the application side not the database side. Those error codes have nothing to do with SQL Server. Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
monkeybite
Posting Yak Master
152 Posts |
Posted - 2005-04-19 : 10:58:24
|
You can capture the Ad-hoc message from RAISERROR like this, and you can also test the SqlExecption.Number value:private void someMethod(){ try { // Do a RAISERROR inside of a SQL block like // RAISERROR('You did something wrong with the value "%s"', 16, 1, @param1) } catch (SqlException sqle) { lblMessage.Text = sqle.Message; } catch (Exception err) { // Do something else with the exception }} ~ monkey |
 |
|
|