Results 1 to 3 of 3

Thread: ERROR_MESSAGE() not returning RaiseError's message

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    N42 29.340 W71 53.215
    Posts
    422

    Question ERROR_MESSAGE() not returning RaiseError's message

    I'm running a stored procedure (SQL Server 2005) that's doing an Insert Into a table.

    The table has a trigger that is using RaiseError because a value is invalid.

    The problem:
    When I run the stored proc directly in the Management Studio
    it returns a "canned" SQL error message in the Messages window,
    plus the errmsg from the trigger's RaiseError.
    This is great because it give me nice detail.

    But, I want to capture that error info in a table to send to myself.
    So, I added
    BEGIN TRY
    -- code
    END TRY
    BEGIN CATCH
    -- get all the error info
    END CATCH

    However, the ERROR_MESSAGES() function only returns the canned SQL msg,
    NOT the msg from the trigger's RaiseError.
    So, now I've lost the detail.

    Any idea how I can get the triger's error?
    I don't own the trigger, so edting that isn't an option.

    Thanks, DaveBo
    "The wise man doesn't know all the answers, but he knows where to find them."
    VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: ERROR_MESSAGE() not returning RaiseError's message

    What does your catch look like?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    N42 29.340 W71 53.215
    Posts
    422

    Re: ERROR_MESSAGE() not returning RaiseError's message

    Code:
          BEGIN CATCH
    	INSERT INTO AA_ErrorLog (
    	  ErrSource, ErrLine, ErrNum, ErrMsg, Az_ID, Last_Name, First_Name)
    	VALUES(
    	  ERROR_PROCEDURE(), ERROR_LINE(), ERROR_NUMBER(), ERROR_MESSAGE(), 
    	  IsNull(@AZ_ID,'NULL'), IsNull(@LastName,'NULL'), IsNull(@FirstName,'NULL') )
          END CATCH
    "The wise man doesn't know all the answers, but he knows where to find them."
    VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width