Catching SQL Server Error Messages

  • I believe that there may be no solution to this problem, but....

    I want to be able to catch SQL Server Error Messages (note: not @@error, but the error that would be thrown to ADO, .NET, etc.) within a stored procedure, and write them to a table. 

    Here's why:  I have a staging table that I am using during a data import procedure. I have a cursor that reads from the staging table and writes to the transactional table.  If the record can be written, it is deleted from the staging table. In the event that an error occurs the record stays in the staging table, and I want to be able to write the error to a column for that record in the staging table so that someone who comes along later to examine the error can see what the error was.  @@Error is not a suitable thing to write since it does not contain any context for the error.  The data import procedure needs to be self contained (i.e. I cannot throw the error to an .NET application and write it to the table) for performance and business reasons.

    Any ideas?

  • I asked the same question I while ago, and received the linke to this article:

    http://www.sqlservercentral.com/columnists/ajethva/capturingtheerrordescriptioninastoredprocedure.asp

    Unfortunately, I wouldn't work for me, as we can't use server-wide settings (or extended procedures) for our applications. But otherwise it seems like a very neat solution.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply