Sql依赖项查询通知错误

本文关键字:通知 错误 查询 依赖 Sql | 更新日期: 2023-09-27 18:34:14

我正在尝试让查询通知在SQL Server 2012上运行。 我正在按照此链接中的教程进行操作:http://www.codeproject.com/Articles/144344/Query-Notification-using-SqlDependency-and-SqlCach

我最终得到的是OnChange事件不断被触发。 SqlNotificationEventArgs 表示 Info=Invalid, Source=Statement, Type=Subscribe。

从我的研究中,我发现它在订阅时遇到了问题,但我无法弄清楚原因。 在SQL Server事件日志中,我得到的只是

The query notification dialog on conversation handle '{D30D3675-9A2F-E311-A141-8851FB594FAA}.' closed due to the following error: 
'<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.

我已经逐步解决了常见问题,例如确保我使用的是由两部分组成的表名,并且我的查询没有执行任何禁止的操作。 下面是设置事件的代码:

 public DataTable RegisterDependency()
 {
     this.CurrentCommand = 
           new SqlCommand("Select CategoryID,CategoryName,Description from dbo.[Categories]", this.CurrentConnection);
     this.CurrentCommand.Notification = null;

     SqlDependency dependency = new SqlDependency(this.CurrentCommand);
     dependency.OnChange += this.dependency_OnChange;
     if (this.CurrentConnection.State == ConnectionState.Closed)
         this.CurrentConnection.Open();
         try
         {
             DataTable dt = new DataTable();
             dt.Load(this.CurrentCommand.ExecuteReader(CommandBehavior.CloseConnection));
             return dt;
         }
         catch { return null; }
}

我不知道接下来要检查什么。 任何帮助,不胜感激。

Sql依赖项查询通知错误

事实证明,问题出在表定义上。 "说明"列是"ntext"类型,不适用于通知。

供未来的读者使用。

Closed event notification conversation endpoint with handle '{ABC123}', due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.

当我的<NotificationService><ConnectionString>与我的<ApplicationService><OnNotification>数据库连接值不匹配时,我收到此错误。 (一个小错别字,但足以甩掉它)