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>'.
2 部構成のテーブル名を使用していることや、クエリが禁止されていることをしていないことを確認するなど、よくある懸念事項を確認しました。イベントを設定するコードは次のとおりです。
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; }
}
次に何をチェックしようか迷っています。どんな助けでも大歓迎です。