Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
MorningZ
Starting Member
44 Posts |
Posted - 2006-05-15 : 19:57:09
|
Good evening...I am looking to throw my own error inside a PROC i am writing so I can catch it back in the ASP.NET applicationThis is mainly for the "Membership.GetUser" functionality and i'd like to know "why" it failed to get the row from my custom providerSo I'm not really sure what the SQL2005/T-SQL equiv of:Throw New Exception("Some Custom Error Thrown")that works in VB.NETThanks in advance |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-05-15 : 20:12:41
|
The RAISERROR command will do the trick:UPDATE myTable SET col1=0 WHERE col1=2IF @@ROWCOUNT=0RAISERROR('No rows were updated.', 16, 1)This is a pretty dumb example, but it illustrates the syntax. Look in Books Online for more examples under "RAISERROR". |
|
|
MorningZ
Starting Member
44 Posts |
Posted - 2006-05-15 : 22:09:16
|
Perfect... much thanks |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-05-16 : 04:15:44
|
Also in 2005 you can use TRY..CATCH blocks which would allow you to use a custom error handler, eg a .NET assembly if you wanted.-------Moo. :) |
|
|
MorningZ
Starting Member
44 Posts |
Posted - 2006-05-16 : 08:53:10
|
quote: Originally posted by mr_mist Also in 2005 you can use TRY..CATCH blocks which would allow you to use a custom error handler, eg a .NET assembly if you wanted.-------Moo. :)
I'm not really trapping actual errors though, so "Try" would always execute...it's just that when someone logs in, there's a few situations that their account could be in:- Not approved yet- Locked (too many invalid attempts)- Doesn't Exist- Wrong site (i'm going to have multiple sites point to this same codebase/database)but running into any of those will not make an actual error |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-05-16 : 09:33:53
|
Ahh, yes. You could handle this from within SQL (using an assembly) though, if you wanted.-------Moo. :) |
|
|
|
|
|