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
 General SQL Server Forums
 New to SQL Server Programming
 Retrieving Error Message Text

Author  Topic 

TeenageKicks
Starting Member

9 Posts

Posted - 2006-01-19 : 16:44:04
Hi,

I'm new to SQL Server and I'm building an SQL Server 2000 database that will be loaded and accessed via stored procedures.

One of the requirements is that I have to log any errors that occur to an error log table containing the date/time, error code and the exact error text - ie containing problem table name, column name, etc.

The problem I'm having is that I can't see a way of capturing the exact error text in a stored procedure. The only thing that seems available is @@error which only returns the error code - not the actual text. I could go to the sysmessages table using the error code but that'll only return the message template containing parameters - not containing the actual table/column/etc causing the problem.

Does anyone have any ideas how to retrieve the exact error message text?

Any help would be most appreciated!

Regards,

Chris

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-20 : 00:27:39
Start with these
http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

TeenageKicks
Starting Member

9 Posts

Posted - 2006-01-20 : 05:39:41
Thanks for the links...informative but not much help in this case. It seems that you cannot access the actual error message in an SQL Server 2000 stored procedure.

The problem I've got is that we're executing the stored procedures remotely via a mainframe job (using Connect:Direct to trigger a .bat executable file on the SQL Server machine which in turn executes the stored procedure). The OSQL command in the .bat file to execute the stored procedure allows you to specify a text log file where the job messages are to be written so I think I'll have to go back to the business and tell them that's the best they'll get!

Unless anyone else has any other ideas?...
Go to Top of Page
   

- Advertisement -