RAISERROR DOES NOT SHOW MESSAGE

  • Dear,

    I have created a "After Insert" trigger in one of my tables. It will raise an error message if conditions are not met. When I click on "Save" button, no error message appears but it prevents transaction from inserting rows.

    Please guide me the way so that an error message appears if conditions are not met.

    Thanks

  • Don't use triggers to restrict allowed data in a table. Use CHECK constraints instead.

    If you insist using a trigger, use ROLLBACK to prevent the changes to the destination table. RAISERROR won't always be enough.

    What you display in the application is totally up to you, but you should get the error if raised correctly. Be aware that severity below 10 is interpreted as a PRINT message and isn't forwarded to the application as a real error.

    -- Gianluca Sartori

  • @spaghettidba,

    I have used rollback and also require to display an error message. But the message is not appearing. I have used the following code.

    begin

    RAISERROR ('Sorry!You have entered more discount',16,1);

    ROLLBACK;

    end

  • Quick suggestion, add WITH NOWAIT to the RAISERROR

    😎

    BEGIN

    BEGIN TRAN;

    RAISERROR ('Sorry!You have entered more discount',16,1) WITH NOWAIT;

    ROLLBACK;

    END

  • I tried all the way out but in vain. I am not getting any clue.

  • shohelr2003 (11/4/2014)


    Dear,

    I have created a "After Insert" trigger in one of my tables. It will raise an error message if conditions are not met. When I click on "Save" button, no error message appears but it prevents transaction from inserting rows.

    Please guide me the way so that an error message appears if conditions are not met.

    Thanks

    Do you have anything in the GUI to actually capture and report the error?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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