469,917 Members | 1,834 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

How to get the error message rather than the code error

Hi,

After sending a request, I would get the possible error message.
Not the code @@error, nor the exact content of sysmessages, but the
message like it could be in the log file.

TIA,
TSalm

Jun 19 '07 #1
1 1566
TSalm (ts***@free.fr) writes:
After sending a request, I would get the possible error message.
Not the code @@error, nor the exact content of sysmessages, but the
message like it could be in the log file.
"Sending a request", that sounds like you are issuing a call from a
client program. In that case you should be able to pick up the error
message. If you tell which client API you are using, I may even be
able to tell you how.

If you mean in a stored procedure, it depends on which version of SQL
Server you are on. If you are on SQL 2000, the answer is: you can't.

If you are on SQL 2005, you can use the new function error_message()
and its sisters: error_severity(), error_number(), error_state(),
error_procedure() and error_line(). But they only return data, if you
are in a CATCH handler, or a procedure called from a catch handler:

BEGIN TRY
-- Do something bad here
END TRY
BEGIN CATCH
SELECT error_message()
END CATCH
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Bob Stearns | last post: by
17 posts views Thread by Steve Jorgensen | last post: by
6 posts views Thread by Peter Frost | last post: by
8 posts views Thread by jcrouse | last post: by
10 posts views Thread by robert d via AccessMonster.com | last post: by
reply views Thread by erik.erikson | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.