编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

从MySQL引发一个事件并从VB.NET(或类似的东西)处理它?:Raise an event from MySQL and handle it from VB.NET (or something similar)?

FengJin-cv mysql 2022-5-11 10:31 5人围观

腾讯云服务器
从MySQL引发一个事件并从VB.NET(或类似的东西)处理它?的处理方法

我正在使用MySQL 5.1.39和Visual Studio 2008,并将两者都连接到MySQL Connector Net 6.1.2.

I'm working with MySQL 5.1.39 and Visual Studio 2008 and connecting both with MySQL Connector Net 6.1.2.

我想做的是一旦创建了MySqlConnection对象,当给定表中特定行中的字段更新时,便能够处理引发的事件".

What I'd like to do is once a MySqlConnection object is created, be able to handle the "event raised" when a field in a specific row in a given table is updated.

我的意思是,当该表中的值已从任何其他应用程序手动更改或修改后,我想在打开的VB.NET应用程序中接收信号.到目前为止,我是通过打开的VB.NET应用程序每隔X秒检查一次该表来完成此操作的,但是我想知道是否可以采用更好的方法来完成该操作.

I mean, when that value in that table has been manually changed or modified from any other application, I'd like to receive a signal in my opened VB.NET application. Until now, I do it from opened VB.NET application checking that table every X seconds, but I wonder if it could be done in a better way.

非常感谢您的关注和时间.

Many thanks for your attention and time.

问题解答

理想情况下, SIGNAL 构造,您可以

Ideally, there is the SIGNAL construct, which you can use to field SQL logic errors, but that is not available until MySQL 5.5. It would be best to upgrade to 5.5, if at all possible.

编辑:在5.5之前,并没有很好的解决方案. TRIGGER 可用于获取更新,但不能用于将它们发送到数据库之外.不过请小心,因为如果通过外键动作(例如CASCADE或UPDATE)进行更新,则此操作将不起作用,因为不会为这些动作调用TRIGGER.所以要当心.

There isn't really a good solution for this before 5.5. The TRIGGER works for getting the updates, but not for sending them outside of the database. Be careful, though, as this doesn't work if you're updating through FOREIGN KEY actions, such as CASCADE or UPDATE, as TRIGGERs are not called for these actions. So watch out for that.

DELIMITER $$ CREATE TRIGGER my_trigger_name AFTER UPDATE ON my_table_name FOR EACH ROW BEGIN CALL my_on_update_procedure(NEW.entry_name, NEW.whatever_else) END $$ DELIMITER ; 

my_on_update_procedure的操作取决于您.您的解决方案可能是5.1.39的最佳选择(由于可伸缩性问题,我不建议您锁定),但5.5将为您提供SIGNAL结构,这正是您想要的(所以请升级!).

What my_on_update_procedure does is up to you. Your solution is probably the best bet for 5.1.39 (I would not recommend locking due to scalability issues), but 5.5 would give you the SIGNAL construct, which is exactly what you want (so upgrade!).

这篇关于从MySQL引发一个事件并从VB.NET(或类似的东西)处理它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^