Query Notification Messages
A query notification message contains XML. Each message includes the reason the message was created and the notification message included when the notification was created.
Attributes on the QueryNotification element identify the reason for the message, while the Message element contains the notification ID for the subscription. For example, the XML document shown below is a complete query notification message, reformatted for readability:
<qn:QueryNotification xmlns:qn="http://schemas.microsoft.com/SQL/Notifications/QueryNotification" Type="change" Source="data" Info="insert"> <qn:Message>http://mysite.microsoft.com/catalog.aspx?Category=Cars</qn:Message> </qn:QueryNotification>
This query notification message reports that an INSERT statement changed the data for the subscription with the message, "http://mysite.microsoft.com/catalog.aspx?Category=Cars".
Because the notification is delivered as an XML document, the Database Engine escapes characters that are not valid in an XML document. For example, if the message submitted with the subscription contains the character <, the returned XML escapes this character to <.
The following tables list the values for each attribute. SQL Server only produces certain combinations of attributes. For example, because a Type of change requires that the subscription was created, a Type of change is never combined with a Source of statement.
Query notification messages fall into two main types, distinguished by the value of the Type attribute. To indicate that the results of the query have changed, the Database Engine creates a message of type change. To indicate that the subscription request failed, the Database Engine creates a message of type subscribe. The values of the other two attributes indicate the precise reason that SQL Server created the message.
When a change occurs that may affect the results of a query, SQL Server produces a message of type change. The following table describes change messages:
One or more of the tables referenced in the query was truncated.
SQL Server processed an INSERT statement on one or more of the tables referenced in the query.
SQL Server processed an UPDATE statement on one or more of the tables referenced in the query.
SQL Server processed a DELETE statement on one or more of the tables referenced in the query.
The subscription time-out expired. None is not an available result on the client side. None on the server side is translated to either UNKNOWN or ERROR on the client side.
One of the underlying objects used by the query was dropped.
One of the underlying objects used by the query was modified.
SQL Server started.
An internal error occurred in SQL Server.
The notification subscription was removed due to the state of SQL Server, for example, a heavily loaded server.
When SQL Server can not create a subscription, the server immediately produces a message of type subscribe. The following table describes subscribe messages.
The command submitted contained a SELECT statement that does not meet the requirements for query notification.
The command submitted contained a statement that does not support notifications (for example, an INSERT or UPDATE).
A previous command in the transaction contained a statement that does not support notifications (for example, an INSERT or UPDATE)
The connection options were not set appropriately when the command was submitted.
The isolation level was not valid for query notification (SNAPSHOT isolation level).
query template limit
A table specified in the query has reached the maximum number of internal templates.