Question

I'm trying to get Query Notifications working on SQL Server 2012. I was following the tutorial at this link: http://www.codeproject.com/Articles/144344/Query-Notification-using-SqlDependency-and-SqlCach

What I end up with is the OnChange event getting constantly fired. The SqlNotificationEventArgs says Info=Invalid, Source=Statement, Type=Subscribe.

From my research, I see it's having problems subscribing, but I can't figure out why. In the SQL Server event logs, all I get is

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

I've stepped through the common concerns, like making sure I'm using a two part table name, and that my query isn't doing anything forbidden. Here's the code that sets up the event:

 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; }

}

I'm at a loss as to what to check next. Any help is appreciated.

Was it helpful?

Solution

Turns out the issue was with the table definition. The column "Description" is an 'ntext' type and that doesn't work with notifications.

OTHER TIPS

For future readers.

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

I got this error when my <NotificationService><ConnectionString> did not match my <ApplicationService><OnNotification> database connection values. (A small typo, but enough to throw it off)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top