Custom Error Message

  • Hi,

    BEGIN TRY

    CREATE TABLE [dbo].[TestTable]

    (

    ID INT NOT NULL PRIMARY KEY

    )

    RAISERROR('Everything is OK!', 5, 1)

    END TRY

    BEGIN CATCH

    RAISERROR('There was a problem!', 16, 1)

    END CATCH

    I'm using the custom error message like above. Then the error is catched as

    Msg 2714, Level 16, State 6, Line 1

    There is already an object named 'TestTable' in the database.

    But I don't want to display the error Number,error state and serverity. Just want to display the user as

    "There is already an object named 'TestTable' in the database."

    Thanks in advance.

    Regards

    GuruPrasad.G

  • What about like this:

    BEGIN TRY

    IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TestTable]') AND type in (N'U'))

    raiserror('There is already an object named ''TestTable'' in the database.',5,1)

    ELSE BEGIN

    CREATE TABLE [dbo].[TestTable]

    (

    ID INT NOT NULL PRIMARY KEY

    )

    RAISERROR('Everything is OK!', 5, 1)

    END

    END TRY

    BEGIN CATCH

    RAISERROR('There was a problem!', 16, 1)

    END CATCH

    Regards,

    Igor Micev

    Igor Micev,My blog: www.igormicev.com

  • This works for me

    BEGIN TRY

    CREATE TABLE [dbo].[TestTable]

    (

    ID INT NOT NULL PRIMARY KEY

    )

    RAISERROR('Everything is OK!', 5, 1)

    END TRY

    BEGIN CATCH

    RAISERROR ('There was a problem!',0,0)

    END CATCH

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Hi Igor Micev,bitbucket-25253

    Thanks for your reply.

    In bitbucket-25253 reply Error message is shown as warning/information in sql .So, I'm not able to get/display in front end(C#/VB.net)

    Regards

    GuruPrasad.G

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

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