I'm trying to write a vb.net application that usesSqlDependency
. The dependency will be triggered when data is added to the database. I'm wondering开发者_运维技巧 if it's possible to have the dependency return the data/query that triggered it.
Currently i have to have the onchange
event trigger a select statement to refresh the data i have cached. Is it possible to just have the dependency return the new data that triggered it
i.e. the following is added to a table, the table has 2 fields (id, data)
id: 1
data: hello
When this is added the dependency onchange event will be fired and
id: 1
data: hello
will be returned
See http://rusanu.com/2006/06/17/the-mysterious-notification/ for an explanation how SqlDependency works under the covers. It is not possible to get the data changes along with the notification. While there are technologies around Change Tracking and Change Data Capture, but for a multitude of reasons, they are not appropiate for applications monitoring changes. They are intended for Data Synchronization (Sync Framework) and would have to be pulled for change, which in effect kills any attempt to use them for caching.
The ONLY proactive notification change technology is Query Notificatio, see more details in my link.
No. I don't think that's possible with SqlDependency. You could either use triggers, or use the change tracking in SQL 2008.
精彩评论