Very quick question – if I deploy a WPF application to a few users, can I use an SQL Dependency? In other words, I was thinking about using an SQL Dependency (although I can’t figure it out, but that’s another topic…) in a WPF program, but I’ve read tidbits that this doesn’t work if multiple users subscribe to it or something. Is this true? And if so, whats the best way to do it? I’m simply trying to figure out the best way for the WPF program to recognize when a new row is added to a database (and then to pull the information in that row)
Thanks!
EDIT: Would it be easier / more effective to just use a background worker, and an endless loop that queried the database every few seconds? And in the event that the number of rows increases, then do something?
P.S. Using C# and SQL Server 2008 R2 Express
Yes, you can use
SqlDependencyandSqlCacheDependencyin a WPF application.You will have to make sure that you call
SqlDependency.Startat the correct moment andSqlDependency.Stopwhen you’re done or when the program exits. Then you can point the dependency to aSQLCommandobject and make sure that you subscribe to theOnChangeevent.Here is a nice example with both a WPF and ASP.NET implementation.