CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Error Message

  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    Error Message

    I've got a procedure like this..

    Code:
    CREATE PROC dbWBS_sp_ExecuteQuery
    (
    	@QueryString		VARCHAR(8192),
    	@ErrMsg				VARCHAR(512) OUTPUT
    )
    AS	
    BEGIN	
    	EXEC @QueryString
    END
    Now if there is any error in the querystring I want to store that error message in this variable @ErrMsg. How can I accompalish this??

    Thanks in Advance

  2. #2
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: Error Message

    SQL Server 2000 or 2005?

  3. #3
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Error Message

    Quote Originally Posted by andreasblixt
    SQL Server 2000 or 2005?
    2005

  4. #4
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: Error Message

    Try this:
    Code:
    CREATE PROCEDURE uspTryExecute
    	@QueryString nvarchar(max),
    	@Error nvarchar(2048) = NULL OUTPUT
    AS
    BEGIN TRY
    	EXECUTE(@QueryString);
    END TRY
    BEGIN CATCH
    	SET @Error = ERROR_MESSAGE();
    END CATCH;
    GO
    
    DECLARE @Message nvarchar(2048);
    EXEC uspTryExecute N'SELECT a, b, c FROM NonExistentTable;', @Message OUT;
    SELECT @Message;
    GO
    Last edited by andreasblixt; November 15th, 2007 at 08:41 AM.

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

Featured