user2541163
user2541163

Reputation: 737

Detect Database Query Update

The scenario is as follows:

  1. Client A and Client B both logged into the application.
  2. Client A and Client B have their gridview populated(shows uploaded files).
  3. Client A uploads a file to database.
  4. Client B must detect that there is a data added(the file which Client A uploaded) and repopulate the gridview again.

I need to know the flow which step 4 works. I read about using SqlDependency and have looked at this article http://rusanu.com/2007/11/01/remove-pooling-for-data-changes-from-a-wcf-front-end/
However if I'm not wrong this article uses Notification Services which is deprecated in SQL Server 2008. I would also like to know how to register code in the client when it is detected that there is a change in query result in database. Thanks

Edited
Currently the options are SqlDependency, trigger, WCF, Observer pattern. If anyone knows if anyone of these solutions can/cannot be implemented in my scenario please feel free to comment and let me know.

Upvotes: 1

Views: 970

Answers (2)

OzrenTkalcecKrznaric
OzrenTkalcecKrznaric

Reputation: 5646

You are wrong, article does not use Notification Services. Following is used in the article:

  • on top there is a web service (WCF duplex channel) that the client calls; clients has a callback that is called when something changes in data; this can be used with database polling as well; on the other hand the article uses more advanced technique to react on data changes
  • in the underlying data access layer, app server uses ordinary ADO.Net connection to employ the SqlDependency; using this technology, subscriber attaches an event which is going to get fired when data is changed; server will then immediately send the updated data to client
  • on the database side itself, SQL Server Service Broker is used by SqlDependency internally to avoid polling; you can do this manually by yourself if you know how to manipulate Service Broker objects

So, none of this technologies uses deprecated Notification Services. Everything you need to start (even if you use SQL Server 2012) is described in that article.

Upvotes: 1

Mangoose
Mangoose

Reputation: 922

You can do this in Application layer. You can have a centralize method/class to update files in your database. Then you can register observers(Observer pattern) to get notification of any updates. In this way you can refresh multiple clients when data changes in database.

Above suggestion will work only if there is no data change from other process or direct DB updates.

Upvotes: 2

Related Questions