Detecting changes to database tables

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 12-May-2008 22:39:08   

I'd like others thoughts on the best way to detect changes in a database e.g. certain tables. I'm not sure if there are any LLBLGEN specific features that would help, however the SqlDependency seems an obvious one which is SQL Server specific.

I'm actually developing a system tray application which I'd like notified when some of the key entities it monitors change state.

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 12-May-2008 22:47:53   

I don't think this is an easy problem. I've "solved" it with polling and triggers.

When something happens I'm interested in happens in the database I insert a record into an event table it includes a column of the time the event happened and in indexed descending on this column.

My client periodically or on request sees if there are any records with a date newer than the last time it asked. If there are it reacts.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-May-2008 12:58:05   

One approach could be this one: - create a trigger which acts on update/insert/delete - the trigger calls a proc, depending on the db type, you need an external proc or a proc which can call java code/.net code - the proc is your push system, so the proc effectively pushes a value out to a client for example. This requires some configuration but it is doable that the client registers itself with the db system or a service and the service registers itself with the db. The proc then creates a connection with the service and sents the change to the service - the service sends a message to all registered clients that a change happened.

This avoids needless polling. However it also requires some routing in code which is very app specific and less maintainable. You can also go the polling route with a trigger.

Frans Bouma | Lead developer LLBLGen Pro