Special Considerations When Using Query Notifications

本文详细介绍了使用SQL Server查询通知时需要考虑的特殊情况,包括支持的通知查询类型限制、快速更新时的应用行为调整以及事务处理等方面。

Special Considerations When Using Query Notifications

 

Applications that use query notification features need to take into account the following special considerations.

 

Valid Queries

Query notifications only support certain Transact-SQL statements.

 

First, to support notifications, queries must not contain:

 

  • Derived tables.

 

  • Rowset functions.

 

  • The UNION operator.

 

  • Subqueries.

 

  • Outer or self-joins.

 

  • The TOP clause.

 

  • The DISTINCT keyword.

 

  • A COUNT(*) aggregate.

 

  • AVG, MAX, MIN, STDEV, STDEVP, VAR, or VARP aggregates.

 

  • User-defined aggregates.

 

  • A SUM function that references a nullable expression.

 

  • The full-text predicates CONTAINS or FREETEXT.

 

  • A COMPUTE or COMPUTE BY clause.

 

  • Aggregate expressions if GROUP BY is not specified in a select list. If GROUP BY is specified, the select list must contain a COUNT_BIG(*) expression, and cannot specify HAVING, CUBE, or ROLLUP.

 

  • An INTO clause.

 

  • Conditions that will preclude results from changing (e.g. WHERE 1=0).

 

  • FOR BROWSE (or be running with SET NO_BROWSETABLE ON).

 

  • A READPAST locking hint.

 

  • Second, queries must not reference:

 

  • Temporal tables or table variables.

 

  • Tables or views from other databases or servers.

 

  • Any other views or table-valued functions.

 

  • Any system tables or views.

 

  • Any nondeterministic function, including ranking and windowing functions.

 

  • Any server global variables.

 

  • Any Service Broker queue.

 

  • Synonyms.

 

Finally, queries must reference a base table or view.

 

Rapid Updates

An application that uses Query Notifications must take into consideration cases where a notification occurs immediately. When data is changed on the server, a notification message will be sent to the appropriate Service Broker queue. Applications need to reregister to receive additional notifications. Therefore, if a data set is updated quickly by multiple applications, an application could receive a notification, retrieve the data, and then get another update notification almost immediately after the cache has been refreshed. Applications that use Query Notifications must be written to take this case into account. If an application uses data that is constantly updated, another strategy for caching data may be more appropriate.

 

Transactions

If multiple modifications are made to a set of data with a registered notification request, and those changes occur within a transaction, only a single notification event will be sent.

 

Service Account for SQL Server

An application will not receive notifications from an instance of SQL Server that uses the Local System account as the service account.

 

(Attach/Detach,Backup/Restore),Possibly can make this mistake:"An exception occurred while enqueueing a message in the target queue. Error: 15517, State: 1. Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission.",So Query Notification Couldn't work,try this:ALTER AUTHORIZATION ON DATABASE::[Your DB Name] TO [sa].

转载于:https://www.cnblogs.com/sherrys/archive/2007/05/28/762609.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值