Avuya Mxoli

Avuya Mxoli

  • NA
  • 236
  • 208.7k

Notify C# Desktop application of database changes

Apr 2 2014 8:42 AM
Hi all,
I have been wrecking my brain and using Google resources to the maximum trying to answer this question. I have a web chat application that writes messages to an SQL Server 2012 database whenever a new one gets posted. I have a second application which is desktop, that should notify the users of new messages in the DB posted via the web app. I use the NotifyIcon as the pop up on the user's machine. I have tried using SqlDependency, all the examples do not work. No errors but nothing happens. I have tried different ways, even inserting the data via the desktop app still it does not detect any changes in the database. When I put a breakpoint and check the "dependency" the "HasChanges" property is always False even when I add new rows to the DB.
 
If anyone has another approachI can use, it will be highly appreciated 
 
Code snippet:
 
SqlDependency.Stop(cnnString, "NamesQueue");
SqlDependency.Start(cnnString, "NamesQueue");
SqlDependency dependency = new SqlDependency(cmd, "service=NamesService;local database =ChatDB", int.MaxValue);
dependency.OnChange += new OnChangeEventHandler(OnChange);
 
then the OnChange function which just pops up the notifyIcon.
 
I have tried not addind the queue and service still no luck.
I have enabled service broker in SQL and followed all the steps but still...