In Transact-SQL you can get the error number from @.@.Error, but is there
anything to get the message?
Here's an example that forces a FK error and tries to get the message from
sysmessages. As you will see the error message doesn't contain the
parameter values. Anybody have any ideas? I'm still using SQL Server 2000,
so I can't use the new 2005 error functions.
DECLARE @.intID INT
DECLARE @.intError INT
DECLARE @.strErrorMessage VARCHAR(4000)
UPDATE OrderDetails SET OrderID = 0 WHERE OrderID = 42
SELECT @.intError = @.@.ERROR
IF @.intError <> 0
BEGIN
SELECT @.strErrorMessage = description FROM master.dbo.sysmessages WHERE
error = @.intError
PRINT 'Error Number:' + CAST(@.intError AS VARCHAR)
PRINT 'Error Message:' + @.strErrorMessage
ENDPlease ignore this post. I triple-posted it by accident.
Tuesday, March 20, 2012
Retrieving error messages
Labels:
database,
error,
example,
forces,
messagehere,
messages,
microsoft,
mysql,
number,
oracle,
retrieving,
server,
sql,
thereanything,
transact-sql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment