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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Returning error codes

Author  Topic 

hasanali00
Posting Yak Master

207 Posts

Posted - 2005-04-05 : 17:45:40
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

38200 Posts

Posted - 2005-04-05 : 17:48:35
The list is in SQL Server Books Online.

Tara
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-04-05 : 19:50:21
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 - 2005-04-06 : 04:43:59
thanks
Go to Top of Page
   

- Advertisement -