Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2006, 01:06 PM
Registered User
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default news module - adding new categories

Hello

I am confused about some of the code in the News module about how to create a new News category.

The database has a stored procedure called InsertCategory which inserts a new category into the database.

This procedure will raise an error if the category already exists and returns a value of 99.

What is the significance of the number 99? Also what is the point of returning a value of 99? The method calling the procedure does not access the return value.

I'm a bit hazy on raiserror. Will this raiserror statement cause the execution of the stored procedure to stop

RAISERROR ('Insert of Category failed', 16, 1)

Thanks very much
andrea

 
Old June 26th, 2006, 11:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's the SQL 2K method of raising an exception. It doesn't understand real exceptions, but it just aborts and returns the specified error code.
 
Old June 27th, 2006, 01:27 PM
Registered User
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thanks for your reply. I'm still a bit lost about the return value. Here is the extract from the SP

IF @@ERROR > 0
        BEGIN
        RAISERROR ('Insert of Category failed', 16, 1)
        RETURN 99
        END
    END

Will the number 99 be returned because it happens after the raiseerror?

Why return the number 99? Is there any significance?

Thanks a lot
andrea

 
Old June 30th, 2006, 07:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The idea is that it only terminates processing if the error code is a fatal code. That bit of code you're talking about uses error code 16, which is not fatal. Therefore, the 99 will be returned to the caller, and the caller can also test to discover the error 16. I don't remember what Marco is doing in that code, but you should be able to understand it.

Unfortunately, SQL Server error handling has always been a weakness in my mind. Even though they added real exceptions in 2005, they still don't have as much functionality in exceptions as we'd like, and your current transaction may become unusable in the catch, depending on the nature of the exception. This does make sense, but you need to study up on it before using it so it doesn't bite you.

Use google if you want more info on it. There's a ton of hits if you search for Raiserror.

Eric





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accounts module - adding new users andieje BOOK: ASP.NET Website Programming Problem-Design-Solution 1 June 26th, 2006 11:07 PM
Module News Problem thanhh83 BOOK: ASP.NET Website Programming Problem-Design-Solution 9 May 16th, 2006 09:41 PM
Adding Categories to Message board in Ch.16 PlaGuE BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 November 19th, 2005 08:24 PM
News Module/storing html in databases groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 8 September 21st, 2004 06:54 AM
News Manager Only shows First 2 Categories cohansh1 BOOK: ASP.NET Website Programming Problem-Design-Solution 4 July 23rd, 2004 11:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.