Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:43:35+00:00 2026-06-09T03:43:35+00:00

I’ve been working with Service Broker a few weeks now and while tracing a

  • 0

I’ve been working with Service Broker a few weeks now and while tracing a conversation, I discovered something odd… The conversation seems to have an additional message in queue at the end which also causes an error to occur.

From what I understand, the conversation dialog should go as follows:

  1. Trigger fires and calls begin conversation
  2. Initiator service places message on queue
  3. Target service fires a stored proc, receives the message and ends the conversation
  4. Initiator service fires a stored proc, receives the message and also ends the conversation.

What’s happening is there’s an extra message in the queue at the end which fires off the stored proc again, but the details (i.e. conversation_handle) is null. It also throws an error: Conversion failed when converting from a character string to uniqueidentifier. To get around the error, I cast the conversation_handle to varchar then check for null. Seems stupid to me that I would have to do this.

Update: The error has gone away – I believe it was happening when I was attempting to log the conversation_handle (which was null).

What’s the proper way to end the conversation without getting the extra message at the end?

Here’s what I have now:

alter proc dbo.MessageProcessor
as

begin

    set nocount on;
    set xact_abort on;

    declare @xactState smallint

    declare @handle uniqueidentifier, 
            @responseXml xml, 
            @messageType sysname;

    begin transaction;
    begin try

        ;receive top(1)
            @messageType = message_type_name, 
            @handle = conversation_handle, 
            @responseXml = message_body
        from dbo.MessageQueue

        if(@handle is not null)
        begin

            if (@messageType = N'DEFAULT')
            begin

                save transaction MessageProcessor_Tran

                begin try

                    -- doing work here

                end try
                begin catch

                    select @xactState = xact_state()

                    if(@xactState = -1)
                    begin
                        rollback;
                        raiserror(N'Unrecoverable error', 16, 1)
                    end
                    else if(@xactState = 1)
                    begin
                        rollback transaction MessageProcessor_tran
                    end

                    -- log error information

                end catch
            end 
            else if (@messageType = N'http://schemas.microsoft.com/SQL/ServiceBroker/Error')
            begin
                declare @errorNumber int,
                        @errorMessage nvarchar(4000);

                with xmlnamespaces (DEFAULT N'http://schemas.microsoft.com/SQL/ServiceBroker/Error')
                select @errorNumber = @responseXml.value ('(/Error/Code)[1]', 'INT'),
                    @errorMessage = @responseXml.value ('(/Error/Description)[1]', 'NVARCHAR(4000)');
                -- log error
            end

            end conversation @handle
            set @handle = null
        end

        commit
    end try

    begin catch

        declare @error int, 
                @message nvarchar(2048)

        select @error = error_number(), 
            @message = error_message(), 
            @xactState = xact_state();

        if(@xactState <> 0)
            rollback;

        if(@handle is not null)
            end conversation @handle;

        -- log error            
        raiserror(N'Error: %i, %s', 1, 60, @error, @message) with log;

    end catch
end
go
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:43:36+00:00Added an answer on June 9, 2026 at 3:43 am

    Is not any extra message. Is just that your procedure is activated on an empty queue. Your activated procedure code should expect to be activated and RECEIVE to return an empty rowset every now and then (if you only test this with one message at a time it will happen every time, as you observed, under real load it will happen seldom).

    In your code such a case (RECEIVE empty result set) would reflect in NULL @handle, NULL @messageType and NULL @responseXML, which is pretty much what you describe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.