How to: Retrieve Information from a Service Broker Error Message (Transact-SQL)
SQL) 09/02/2025 A message of type is a Service Broker error message.
SQL)
A message of type
is a Service Broker
error message. Messages of this type are XML documents that contain a numeric code for the
error and a description of the error.
- Declare a variable of type
to hold the error code.
- Declare a variable of type
to hold the error description.
- Declare a variable of type
to hold an XML representation of the message body.
the message body from
to
, and assign the results to the
variable of type.
- Use the value function of the
data type to retrieve the error code.
- Use the value function of the
data type to retrieve the error description.
- Handle the error as appropriate for your application. Errors with negative error codes are
generated by Service Broker. Errors with positive error codes are generated by service
programs that ran.
https://schemas.microsoft.com/SQL/ServiceBroker/Error
CAST
END CONVERSATION WITH ERROR
-- The variables to hold the error code and the description are
-- provided by the caller.
CREATE
PROCEDURE
[ExtractBrokerError] (
@message_body VARBINARY (
MAX
),
@code
INT
OUTPUT
,
@description
NVARCHAR (3000)
OUTPUT
)