You are here: Re: How to get the error message rather than the code error « MsSQL Server « IT news, forums, messages
Re: How to get the error message rather than the code error

Posted by Erland Sommarskog on 06/19/07 21:21

TSalm (tsalm@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, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация