@@Error - Getting the correct message

  • If I execute any statement in SQL, @@Error will have an error code associated with that operation.

    master.dbo.sysmessages will have a "decsription" of the message.  It also has placeholders to pass in values, if needed.

    There is also FormatMessage which will take an Error Code, and "N" parameters to return a nice message.

    My question is:  How do I put all of these together to get a proper error message?

    Error 547 has this description:

    %ls statement conflicted with %ls %ls constraint '%.*ls'. The conflict occurred in database '%.*ls', table '%.*ls'%ls%.*ls%ls.

    How do I know how many parameters I will need?  Can I even use this mess to give my users something inteligible?

    Thank You,

      Bryan Clauss

  • Thats because Error Number 547 is a generic 'Foreign Key violation' type error. One suggestion would be to display to the user something like 'Unable to save/modify data due to data mismatch'.

    At the end of the day, no matter how friendly/unfriendly the error message displays, it will come to you to fix anyway!


    Kindest Regards,

  • I was using Error # 547 as an example.  (This is what MS SQL Help had as an example.)

    If I recieve an error, should I just pass to the user that there was an Error, and let it go at that?  (Some users are actually good about taking screen shots, and telling us IT people what they were doing at the time, and the rest just tell us (if they even bother) this:  "I got an error last week.  Fix it.")

    Thanks,

    Bryan

  • The complete errormessage will always be sent to the client, it's not even possible in some cases to trap the errormessage in your T-SQL code.

    How it is handled and displayed to the client, though, is dependeing on how the client app is coded.

    /Kenneth

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

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