I am using SqlDependency to monitor database changes. Let's say these are stock quotes to make this example understandable. The application also uses (another) SqlDependeny-Object to monitor changes in static data that are cached in the application.
What I do is launch Dependency on SqlDependency.Start()when the application starts and calls SqlDependeny.Stopwhen the application closes. So far, everything is working well.
Now, when the user selects the stock symbol, another SqlDependency is configured and notifies me of changes on which I can take action. When the user changes the character that he wants to track, I need to configure a new SqlDependency and clean up the old SqlDependency .
My question is: is this true? And how can I clarify specific dependencies? SqlDependency.Stop()is a static method and stops all dependencies - and even there I am not at all sure that the notification subscription on the SQL server is really cleared - or just waiting to start a timeout.
All this begs the question, is it correct to use SqlDependency to perform caching, or if there are other good and easy practices that do this?
source
share