New Posts New Posts RSS Feed: Anyone using SQL Server Query Notification?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Anyone using SQL Server Query Notification?

 Post Reply Post Reply
Author
pnschofield View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Sep-2007
Location: United States
Posts: 18
Post Options Post Options   Quote pnschofield Quote  Post ReplyReply Direct Link To This Post Topic: Anyone using SQL Server Query Notification?
    Posted: 13-Dec-2007 at 1:36pm
I found the tutorial on using Push functionality with SQL Server Notification Services.  I was wondering if anyone had tried using the SQL Server Query Notification with DevForce.  I think our client app could bypass quite a few DataSourceOnly queries if we could have the BOS request Query Notifications for some queries, and then use the Push feature to notify clients when they need to refresh their EntityCache.

I found this article, which describes a method for getting any SqlCommands in  a CallContext to participate in a Query Notification.

If the Fetching event is raised on the PM instance running in the BOS prior to performing the actual database query, I believe I can use the sample code to have the ADO.NET create a SqlDependency and add it to the SqlCommand used by the BOS to perform the actual query.  When SQL Server performs the callback to the BOS, the BOS can perform a Push call back to the client app that performed the original query, notifying it that it should re-fetch the query using DataSourceOnly, to keep the client cache up-to-date.

Has anyone tried this type of approach?

Paul

Back to Top
pnschofield View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Sep-2007
Location: United States
Posts: 18
Post Options Post Options   Quote pnschofield Quote  Post ReplyReply Direct Link To This Post Posted: 18-Dec-2007 at 11:14am
I think I can explain this in another way that would be more interesting.  Imagine if your client app could execute every single query as CacheOnly, even if you absolutely required up-to-date data.  You could enjoy the performance of cached queries, with a guarantee that you'd be only hit the database if the data had changed in the meantime.

Just have the BOS ask for query notifications for each query.  When it receives a notification, the BOS calls a method on the client that originally made the query, to tells it to remove that query from the QueryCache.  The next time that client performs the query (as CacheOnly), it will find that the query doesn't exist in the QueryCache, and will only then execute it against the BOS.  Until that time, the client will be retrieving the query from the local cache, every single time. 

Basically, your client app would never again query the database unless it was necessary to do so. 
Back to Top
Sigi View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Dec-2007
Location: Switzerland
Posts: 1
Post Options Post Options   Quote Sigi Quote  Post ReplyReply Direct Link To This Post Posted: 21-Dec-2007 at 3:34am
We implemented a cache-refresh mechanism based on SqlDependency almost as you described it. We had an  SqlDependency  running on a Custom-Module with  the BOS which was notifying clients about DB-changes.
This works fine. There was/is one problem: SqlDependency does not tell you what exactly changed, even the Column which changed is not reported. This makes it useless for monitoring changes of tables with lots of data.
If all your data access to the Db goes through DevForce, you may wait for a new feature of DevForce providing this functionality in a way you can use it for any size of tables.
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 21-Dec-2007 at 11:14am
Yup. I've wondered about this too. It seems to be a limitation of SQL Server 2005. I'm not even sure if it tells you what row in a table changed (I confess I haven't really looked at it).
 
So if you want to be notified, you should be notified via an AuditTrail table that tells you ... and then either use table triggers or code to add rows to the AuditTrail table.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down