Retrieve SQL Error Info

  • Does anyone know how to get the description text of a SQL Error (eg. "Primary Key violation of ..") into a variable. Like @@ERROR holds the error number, where is the error text?

    Patrick SIMONS, MCP

  • PatrickSimons (4/17/2008)


    Does anyone know how to get the description text of a SQL Error (eg. "Primary Key violation of ..") into a variable. Like @@ERROR holds the error number, where is the error text?

    Unfortunately under SQL Server 2000 you can only use @@ERROR (there is nothing like @@ERROR_MESSAGE). Based on this number you could get more information from master..sysmessages, but these are templates only (with placeholders for object names, ...)

    SQL Server 2005 has improved on this, so in the future when your systems are upgraded you will be able to get the error message.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Andras,

    Concur.

    karthik

  • Found a script that works using DBCC OUTPUTBUFFER

    http://www.sommarskog.se/error-handling-I.html#textretrieve

    Patrick SIMONS, MCP

  • PatrickSimons (4/18/2008)


    Found a script that works using DBCC OUTPUTBUFFER

    http://www.sommarskog.se/error-handling-I.html#textretrieve

    This is indeed a very nice solution, but it comest at a rather high cost (not only it is not 100% reliable, it requires sysadmin privileges :)). Is it really worth?

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Any idea how to clean/initialize the outputbuffer?

    Patrick SIMONS, MCP

Viewing 6 posts - 1 through 5 (of 5 total)

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