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
 Transact-SQL (2000)
 Error Handling

Author  Topic 

hankswart@hotmail.com
Starting Member

2 Posts

Posted - 2005-09-12 : 11:55:56
Hi Guys,

I have been tgrying to figure out a way to add "SQL Generated Error's" to a error logging table.

What I mean by this is that when ever sql generates an error it must send the error message to the error table.

E.g.

BEGIN
DECLARE @iErrorNo INT
DECLARE @sErrorMessage VARCHAR(4000)

INSERT INTO Table1
(field1, field2, field3, field4)
VALUES
(1, 'Value 2', 3, 'Value 4')

SET @iErrorNo = @@ERROR

SET @sErrorMessage =
(
SELECT
Description
FROM
master..sysmessages
WHERE
(error = @iErrorNo)
)

IF @@ErrorNo <> 0
BEGIN
INSERT INTO tblError
(ErrMsg)
VALUES
(@sErrorMessage)
END

END

The above works but the object names aren't populated as you would usually do with RAISERROR.

Has anybody ever done anything similar?

Any help would be appreciated...



madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-13 : 00:32:56
Refer these Error handling techniques
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
   

- Advertisement -