Thursday, May 5, 2011

How can I detect when rows are added to a MySQL database?

I have a c# application that picks up files from an ftp server, gets the text out of the file and inserts it into a mysql database. From there it takes the data and ftp's it to another server within our organization.

What I'm looking to do is create a monitoring program that a user can load on their pc that has a grid and is refreshed everytime a new entry is added into the mysql database.

What's the best way to do this? I was going to place a timer control on the form and have it check every 30 seconds or so, but is there any way to do this in real time so that my app knows exactly when the item is added to the database? A control kind of like the FileSystemWatcher but for a database table?

From stackoverflow
  • There are no generic tools that do this. SQL Server has the concept of a SQLDependency, but this is a fairly expensive tool to use.

    Your easiest and simplest option is to do as you thought, with a timer that refreshes.

    Barring that, you could use some sort of message queuing technology like MSMQ and relay a message yourself indicating that an item has been added. Depending on the scale of your project and how important it is that either change notifications come instantly or queries are particularly long or expensive, this may or may not be worth it.

  • I think having the application poll the database is the best solution as it is the simplest and easiest to build, configure, and maintain.

0 comments:

Post a Comment