监控MySQL的表中的C#程序的变化? [英] Monitor MySQL table for changes within a C# program?

查看:463
本文介绍了监控MySQL的表中的C#程序的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以监控在C#应用程序更改MySQL表?我基本上要当数据被插入到表被引发的事件。我唯一​​能想到的,现在是查询表每100ms左右。

Is it possible to monitor a mysql table for changes within a c# application? I basically want an event to be raised when data is inserted into the table. The only thing I can think of now is to query the table every 100ms or so.

推荐答案

如果应用程序和数据库服务器在同一台机器上,你也许可以建立在MySQL中的触发而写出到一个日志文件中插入后,更新,然后创建一个 FileSystemWatcher的观看该日志文件。 FileSystemWatcher的将<一href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed%28v=VS.100%29.aspx"相对=当文件被更改您的应用程序可以反应nofollow的>火灾事件。

If both the application and database server are on the same machine you might be able to set up a trigger in MySQL which writes out to a log file AFTER INSERT, UPDATE and then create a FileSystemWatcher to watch that log file. FileSystemWatcher will fire events when the file is changed that your application can react to.

触发可能是这个样子:

create trigger MyTable_Monitor
after insert, update on MyTable
for each row
begin
select * from new into outfile "path/to/table.log"
end

一个问题,我与上述code看到的是,OUTFILE不能被附加到(尽我可以告诉),所以你可能有问题,如果有被同时执行在一个呼叫中执行多个查询(甚至多个查询不同的客户端)。任何改进的建议是值得欢迎的。

One problem I see with the above code is that the outfile cannot be appended to (best I can tell) so you might have problems if there are multiple queries executed in one call (or even multiple queries executed simultaneously by different clients). Any suggestions for improvement are welcome.

这篇关于监控MySQL的表中的C#程序的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆