title: SQL Service Broker example not working
body: <p>I have two databases on the same instance.</p>
  
  <p>One called ICMS, one called CarePay_DEV1</p>
  
  <p>When a change happens in ICMS (Source), it needs to send a message to CarePay_Dev1 (Destination).</p>
  
  <p>I am new to Broker Services, and am trying to make a message go to the queue. Once that works, I will hopefully get the data into a table in the destination, and that will then be processed by .Net code.  But I just want something to appear in the destination first.</p>
  
  <p>So, step 1: I enable the service on the two databases</p>
  
  <pre><code>-- Enable Broker on CarePay
  ALTER DATABASE CarePay_Dev1
  SET ENABLE_BROKER; 
  
  -- Enable Broker on Source
  ALTER DATABASE ICMS_TRN
  SET ENABLE_BROKER;
  </code></pre>
  
  <p>Step 2: Create the message type on the source and destination.</p>
  
  <pre><code>-- Create Message Type on Receiver:
  USE CarePay_DEV1
  GO
  CREATE MESSAGE TYPE [IcmsCarePayMessage]
  VALIDATION=WELL_FORMED_XML;
  
  -- Create Message Type on Sender:
  USE ICMS_TRN
  GO
  CREATE MESSAGE TYPE [IcmsCarePayMessage]
  VALIDATION=WELL_FORMED_XML;
  </code></pre>
  
  <p>I then create the Contacts, on both databases:</p>
  
  <pre><code>-- Create Message Type on Receiver:
  USE CarePay_DEV1
  GO
  CREATE MESSAGE TYPE [IcmsCarePayMessage]
  VALIDATION=WELL_FORMED_XML;
  
  -- Create Message Type on Sender:
  USE ICMS_TRN
  GO
  CREATE MESSAGE TYPE [IcmsCarePayMessage]
  VALIDATION=WELL_FORMED_XML;
  </code></pre>
  
  <p>I then create the message queues on both databases:</p>
  
  <pre><code>-- CREATE Sending Messagw Queue
  USE ICMS_TRN
  GO
  CREATE QUEUE CarePayQueue
  
  
  -- CREATE Receiving Messagw Queue
  USE CarePay_Dev1
  GO
  CREATE QUEUE CarePayQueue
  </code></pre>
  
  <p>And finally, I create the services on both databases:</p>
  
  <pre><code>-- Create the message services
  USE ICMS_TRN
  GO
  CREATE SERVICE [CarePayService]
  ON QUEUE CarePayQueue
  
  
  USE CarePay_DEV1
  GO
  CREATE SERVICE [CarePayService]
  ON QUEUE CarePayQueue 
  </code></pre>
  
  <p>Now, the queues should be ready, so then I try and send something from the source to the destination:</p>
  
  <pre><code>-- SEND THE MESSAGE!
  USE ICMS_TRN
  GO
  
  DECLARE @InitDlgHandle UNIQUEIDENTIFIER
  DECLARE @RequestMessage VARCHAR(1000) 
  
  BEGIN TRAN
  
      BEGIN DIALOG @InitDlgHandle
      FROM SERVICE [CarePayService]
      TO SERVICE 'CarePayService'
      ON CONTRACT [IcmsCarePayContract]
  
      SELECT @RequestMessage = N'&lt;Message&gt;The eagle has landed!&lt;/Message&gt;';
  
      SEND ON CONVERSATION @InitDlgHandle
      MESSAGE TYPE [IcmsCarePayMessage] (@RequestMessage)
  
  COMMIT TRAN
  </code></pre>
  
  <p>I get: </p>
  
  <blockquote>
    <p>Command(s) completed successfully.</p>
  </blockquote>
  
  <p>But then when I try select from the destination queue, it's empty.</p>
  
  <pre><code>/****** Script for SelectTopNRows command from SSMS  ******/
  SELECT TOP 1000 *, casted_message_body = 
  CASE message_type_name WHEN 'X' 
    THEN CAST(message_body AS NVARCHAR(MAX)) 
    ELSE message_body 
  END 
  FROM [CarePay_DEV1].[dbo].[CarePayQueue] WITH(NOLOCK)
  </code></pre>
  
  <p>Can anyone spot the issue? I can't see where I tell the destination which database to send the message to - which could be part of the issue?</p>