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.

 All Forums
 Old Forums
 CLOSED - SQL Server 2005/Yukon
 How to throw my own exception in a PROC

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 application

This is mainly for the "Membership.GetUser" functionality and i'd like to know "why" it failed to get the row from my custom provider

So I'm not really sure what the SQL2005/T-SQL equiv of:

Throw New Exception("Some Custom Error Thrown")

that works in VB.NET

Thanks 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=2
IF @@ROWCOUNT=0
RAISERROR('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".
Go to Top of Page

MorningZ
Starting Member

44 Posts

Posted - 2006-05-15 : 22:09:16
Perfect... much thanks
Go to Top of Page

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. :)
Go to Top of Page

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
Go to Top of Page

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. :)
Go to Top of Page
   

- Advertisement -