"Shervin Shapourian" <ShShapourian@hotmail.com> wrote in message
news:vpj76ijcj94g57@corp.supernews.com...
> Hi everybody,
>
> I need to trap error messages in my stored procedures and log them. I can
> use @@ERROR global variable to get the error code and look it up in
> sysmessages table to get the description. Then using xp_logevent I log the
> error.
> The problem is this description needs to be formatted. For example if I
try
> to insert NULL into a column which is not nullable, I'll get error #515.
The
> description of error #515 in sysmessages is:
>
> Cannot insert the value NULL into column '%.*ls', table '%.*ls'; column
> does not allow nulls. %ls fails.
>
> Is there a way to get the formatted message? What is the best approach to
> trap errors, filter them, add some additional information to the message
and
> send it to server's event logger?
>
> TIA,
> Shervin
>
>
The text of the message can't be trapped in TSQL, only on the client. There
is a lot of detailed information on this here:
http://www.algonet.se/~sommar/error-...I.html#@@error
Simon