Retriving constraint name and table name from the system error messages

  • We need to retrieve the Constraint Name and Table name from the System error messages through from a procedure.

    For e.g If the insert fails due to Unique constraint error, SQL Server throws system error along with the unique constraint name and table name.

    Please suggest a way by which we can get the constraint name and table name from the error message?

    Thanks in advance.

  • The resolved errormessage must be trapped at the calling side (eg client). Some errors are not possible to trap within a stored procedure.

    All errors are sent to the caller, though, which is where you should trap and handle it.. (calling side may be client app, batch *.cmd file or the like)

    /Kenneth

  • Thanks Kenneth

    But the problem here is we need to catch the error message (tablename and column name) in a calling procedure.

    Any suggestions for that.

  • u mean , u want some method by which u can get the table name and stored procedure name , in which the err occured.

    or u just want to debug a specific error message

     

     

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

  • Unfortunately, the resolved errormessage isn't trappable from within Transact SQL.

    A method to avoid this problem could perhaps be to avoid inserting duplicates into a unique constraint? It's not that hard to do, and there are several ways to ensure that an insert does not attempt to insert if a value already exists.

    /Kenneth

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

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