with the following code, my OnChange event is not raised:
SqlDependency.Start(connectionString);
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
using (SqlCommand command = new SqlCommand(
"SELECT Name, Description FROM dbo.Boms",
conn))
{
SqlDependency dep = new SqlDependency(command);
dep.OnChange += dep_OnChange;
// Execute the command.
using (SqlDataReader reader = command.ExecuteReader())
{
// Process the DataReader.
}
}
I googled for any possible constrains to the query, but my query seems to be ok. The dep object is also properly created, but I tried to insert (successfully) a record inside my Boms table but I received no feedback or event. Inside Sql Server 2012 I see a new queue everytime I launch my application.
I looked for errors into system table but all seems ok.
Any hint to understand at least where is the problem?
Thanks!
private bool CanRequestNotifications() { SqlClientPermission permission = new SqlClientPermission( PermissionState.Unrestricted); try { permission.Demand(); return true; } catch (System.Exception) { return false; } }