SEND (Transact-SQL)

Sends a message by using an existing conversation.

Syntax

SEND
   ON CONVERSATION conversation_handle
   [ MESSAGE TYPE message_type_name ]
   [ ( message_body_expression ) ]
[ ; ]

Arguments

  • ON CONVERSATION conversation_handle
    Specifies the conversation that the message belongs to. The conversation_handle must contain a valid conversation identifier.
  • MESSAGE TYPE message_type_name
    Specifies the message type of the sent message. This message type must be included in the service contract used by this conversation. The contract must allow the message type to be sent from this side of the conversation. For example, the target of the conversation can only send messages specified in the contract as SENT BY TARGET or SENT BY ANY. If this clause is omitted, the message is of the message type DEFAULT.
  • message_body_expression
    Provides an expression representing the message body. The message_body_expression is optional. However, if the message_body_expression is present the expression must be of a type that can be converted to varbinary(max). The expression cannot be NULL. If this clause is omitted, the message body is empty.

Remarks

Important

If the SEND statement is not the first statement in a batch or stored procedure, the preceding statement must be terminated with a semicolon (;), the Transact-SQL statement terminator.

The SEND statement locks the conversation group that the specified conversation handle belongs to.

SEND is not valid in a user-defined function.

Permissions

To send a message, the current user must have SEND permission on the service that the dialog is from. If a remote service binding for the service exists, the user specified in that remote service binding must have RECEIVE permissions on the queue for the service that the dialog is from.

Examples

A. Sending a message

This example starts a dialog and sends an XML message on the dialog. To send the message, the example converts the xml object to varbinary(MAX).

DECLARE @dialog_handle UNIQUEIDENTIFIER,
        @ExpenseReport XML ;

SET @ExpenseReport = < construct message as appropriate for the application > ;

BEGIN DIALOG @dialog_handle
FROM SERVICE [//Adventure-Works.com/Expenses/ExpenseClient]
TO SERVICE '//Adventure-Works.com/Expenses'
ON CONTRACT [//Adventure-Works.com/Expenses/ExpenseProcessing] ;


SEND ON CONVERSATION @dialog_handle
    MESSAGE TYPE [//Adventure-Works.com/Expenses/SubmitExpense]
    (@ExpenseReport) ;

See Also

Reference

BEGIN DIALOG CONVERSATION (Transact-SQL)
BEGIN CONVERSATION TIMER (Transact-SQL)
END CONVERSATION (Transact-SQL)

Other Resources

Service Broker Tutorials

Help and Information

Getting SQL Server 2005 Assistance