Dear Gurus!
I create service with next code:
public void AddEventChanges() { lbNames.Items.Clear(); SqlDependency.Stop(connectionString); SqlDependency.Start(connectionString); using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("Select id_event,name,description from dbo.events", connection)) { cmd.Notification = null; SqlDependency dependency = new SqlDependency(cmd); dependency.OnChange += new OnChangeEventHandler(WaitChange); connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { lbNames.Items.Add(reader.GetString(1)); } } connection.Close(); } } }
And try to stop it with next code:
[OperationContract] public void StopTrackingChanges() { SqlDependency.Stop(connectionString); }But service don't stop
Sometimes it stopped and sometimes it don't. What I am doing wrong?