【问题标题】:SqlDependency Query Notification errorSqlDependency 查询通知错误
【发布时间】:2013-10-07 22:00:44
【问题描述】:

我正在尝试让查询通知在 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; }

}

我不知道接下来要检查什么。任何帮助表示赞赏。

【问题讨论】:

    标签: c# sql sql-server sql-server-2012 sqldependency


    【解决方案1】:

    原来问题出在表定义上。 “描述”列是“ntext”类型,不适用于通知。

    【讨论】:

    • @nimdil - 抱歉,我以为我不被允许这样做。谢谢!
    【解决方案2】:

    为未来的读者。

    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>'.
    

    当我的&lt;NotificationService&gt;&lt;ConnectionString&gt; 与我的&lt;ApplicationService&gt;&lt;OnNotification&gt; 数据库连接值不匹配时,我收到此错误。 (一个小错字,但足以把它扔掉)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多