SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Returning error codes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

hasanali00
Posting Yak Master

207 Posts

Posted - 04/05/2005 :  17:45:40  Show Profile  Reply with Quote
I want to display user-friendly error messages to the user in my web application. So if an error occurs in the sql server, I would like to know what error has occured. Is there any 'official error code' list which i can use. For instance, I think '2601' error code is thrown if the primary key is violated.

Or: how can I return my own error codes??

thanks

tkizer
Almighty SQL Goddess

USA
37123 Posts

Posted - 04/05/2005 :  17:48:35  Show Profile  Visit tkizer's Homepage  Reply with Quote
The list is in SQL Server Books Online.

Tara
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

USA
4184 Posts

Posted - 04/05/2005 :  19:50:21  Show Profile  Visit derrickleggett's Homepage  Send derrickleggett an AOL message  Send derrickleggett a Yahoo! Message  Reply with Quote
You can get the error messages also with:

SELECT
error,
severity,
description
FROM
sysmessages


For user-friendly error messages, you can use RAISERROR and create your own message each time. You can also add messages to sysmessages with sp_addmessage. If you do this, you should use an error number over 50000. The format for RAISERROR is:

1. For a custom message each time.


SELECT * FROM whatever
IF @@ERROR <> 0
 BEGIN
  RAISERROR('Problem with select statement',16,1)
 END



2. If you have created a user-defined message in sysmessages, you can simply reference it.


SELECT * FROM whatever
IF @@ERROR <> 0
 BEGIN
  RAISERROR(60001,16,1)
 END



To find out more, look in Books Online as Tara stated. You can get information by going to the index tab and look at "RAISERROR", "severity levels", and "errors-SQL Server".

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

hasanali00
Posting Yak Master

207 Posts

Posted - 04/06/2005 :  04:43:59  Show Profile  Reply with Quote
thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000