I'm running a .net 4.6.1 application against a Microsoft SQL Server Standard Edition (64-bit) 10.50.1600 RTM, where I use SqlDependency on simple queries (SELECT Column1, Column2, Column3 FROM [dbo].Table WHERE Active] = 1).
I'm using my own Queue and Service:
CREATE QUEUE MyQueue
CREATE SERVICE MyService ON QUEUE MyQueue ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification])
After that, I start the SQLDependency:
SqlDependency.Stop(Configuration.ConnectionString, "MyQueue"); SqlDependency.Start(Configuration.ConnectionString, "MyQueue");
Once that is done, I run all of the queries that I want to watch:
// Create Command... SqlCommand command = new SqlCommand("SELECT Column1 FROM [dbo].Table WHERE Active = 1", _connection); // Create SqlDependency... SqlDependency dependency = new SqlDependency(command, "service=MyService", 60); dependency.OnChange += onDependencyChange; // Run the query (this will activate the SqlDependency) // and pass the results to the onChange delegate using (SqlDataReader reader = command.ExecuteReader()) { ProcessReader(reader); }
But instead of being notified whenever something changes in that table, I only receive Change/Client/Error or Change/Timeout/Error notifications.
If I use the 1-parameter SqlDependency consturctor (thereby using the default service/queue), all seems to be working correctly. =
I did not notice this behavior on my Dev system, but it does show on multiple test systems. Could the SQLServer configuration have something to do with this?