Reputation: 3529
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
Upvotes: 1
Views: 2701
Reputation: 39898
Yes, you can use SqlDependency
and SqlCacheDependency
in a WPF application.
You will have to make sure that you call SqlDependency.Start
at the correct moment and SqlDependency.Stop
when you're done or when the program exits. Then you can point the dependency to a SQLCommand
object and make sure that you subscribe to the OnChange
event.
Here is a nice example with both a WPF and ASP.NET implementation.
Upvotes: 4