How to get the error message rather than the code error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TSalm

    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

  • Erland Sommarskog

    #2
    Re: How to get the error message rather than the code error

    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@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    Working...