如何检测何时将行添加到MySQL数据库?

时间:2022-09-25 15:43:27

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.

我有一个c#应用程序从ftp服务器获取文件,从文件中获取文本并将其插入到mysql数据库中。从那里它将数据和ftp带到我们组织内的另一台服务器。

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.

我想要做的是创建一个监控程序,用户可以在他们的PC上加载具有网格的监控程序,并在每次将新条目添加到mysql数据库时刷新。

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?

最好的方法是什么?我打算在表单上放置一个计时器控件并每30秒检查一次,但有没有办法实时执行此操作,以便我的应用程序确切知道该项目何时添加到数据库?一种控件类似FileSystemWatcher但是对于数据库表?

2 个解决方案

#1


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

我认为让应用程序轮询数据库是最好的解决方案,因为它是最简单,最容易构建,配置和维护的。

#2


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.

没有通用工具可以做到这一点。 SQL Server具有SQLDependency的概念,但这是一个相当昂贵的工具。

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.

除此之外,您可以使用某种消息排队技术(如MSMQ)并自行转发消息,指示已添加项目。根据项目的规模以及更改通知即时或查询特别长或昂贵的重要性,这可能是也可能不值得。

#1


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

我认为让应用程序轮询数据库是最好的解决方案,因为它是最简单,最容易构建,配置和维护的。

#2


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.

没有通用工具可以做到这一点。 SQL Server具有SQLDependency的概念,但这是一个相当昂贵的工具。

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.

除此之外,您可以使用某种消息排队技术(如MSMQ)并自行转发消息,指示已添加项目。根据项目的规模以及更改通知即时或查询特别长或昂贵的重要性,这可能是也可能不值得。