Quantcast
Channel: SQL Service Broker forum
Viewing all articles
Browse latest Browse all 461

Can't stop service

$
0
0

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?


Viewing all articles
Browse latest Browse all 461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>