Dear Gurus!
I use VS 2012 and silverlight project in c#. I am trying to make the event notification system with using signalR.
On the server side I want to use service broker - start notification and when triggered notification - I write the time to static variable. I start notification in Global.asax.cs file as follows:
public class Global : System.Web.HttpApplication { const string ConnectionString = @"Server=TERENTIEVAI; Initial Catalog=road; User ID =dependency_client; Password =111111; Trusted_Connection =False; Integrated Security=True; Asynchronous Processing=True; "; void Application_Start(object sender, EventArgs e) { sqlHelper.lastChangesDate = DateTime.Now; startWaitingChanges(); } public static void startWaitingChanges() { SqlDependency.Stop(ConnectionString); SqlDependency.Start(ConnectionString); using (SqlConnection connection = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand("Select name,description,date_liquidation from dbo.events", connection)) { cmd.Notification = null; SqlDependency dependency = new SqlDependency(cmd); dependency.OnChange += new OnChangeEventHandler(HandleChanges); connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { } connection.Close(); } } } public static void HandleChanges(object sender, SqlNotificationEventArgs e) { sqlHelper.lastChangesDate = DateTime.Now; SqlDependency dep = sender as SqlDependency; dep.OnChange -= new OnChangeEventHandler(HandleChanges);
startWaitingChanges(); }
For the first time the notification always fires. But then it fires sometimes and sometime it not fires.
What I do wrong?