摘要:Using Query Notifications:http://msdn2.microsoft.com/en-us/library/t9x04ed2.aspx
Query Notification不同于Notification Service,最简单的理由是我压根就没装Notification Service也能用它。看BOL文档,Notification Service似乎不只是应用程序级别的服务。
SqlDependency和SqlCacheDependency的实现是不同的。SqlCacheDependency是基于poll模式定时轮询实现的(默认情况),而SqlDependency的是push模型(这意味着SqlDependency性能更高且更可靠)。不过,SqlCacheDependency可以基于SqlDependency实现,但MSDN只是提到“The SqlCacheDependency class also supports integration with the System.Data.SqlClient.SqlDependency class when using a SQL Server 2005 database. ”,但没有给出例子。我Goo了半天才发现Quickstart里面有:http://x/QuickStartv20/aspnet/doc/caching/SQLInvalidation.aspx
SQL Server 2005 EXPRESS也支持Query Notification,但默认似乎是关闭的,并且我也没能在配制工具找到配制界面。事实上不管怎么说只要能开启Broker服务就OK。这可以通过ALTER DATABASE [Your DB Name] SET ENABLE_BROKER命令实现。(后来找到了个相关的,在Management Studio的Object Explorer,Databases|Your DB Name|Properties|Permissions|Subscrib query notifications)
SqlDependency.OnChange Event会报告订阅过程中出现的所有事件,比如订阅失败,而不只是Server端数据改变的情形。假如你在这个事件绑定函数中又重新注册了Query Notification,小心产生死循环。
使用Query Notification是有限制的,并且不是所有的查询都支持(否则产生订阅失败事件),具体规则是:http://msdn2.microsoft.com/en-us/library/aewzkxxh.aspxThe projected columns in the SELECT statement must be explicitly stated, and table names must be qualified with two-part names. Notice that this means that all tables referenced in the statement must be in the same database.The statement may not use the asterisk (*) or table_name.* syntax to specify columns.The statement may not use......[
阅读全文]