简体   繁体   English

在C#中监控mysql数据库

[英]monitoring mysql database in c#

In my Visual Studio C# Project, I set up a connection with my mySQL database. 在Visual Studio C#项目中,我与mySQL数据库建立了连接。 Currently there's a timer which executes a method every 0.1 sec. 当前有一个计时器,它每0.1秒执行一次方法。 This method checks if a value in my mysql-DB has been changed. 该方法检查我的mysql-DB中的值是否已更改。 If the value changed, a label in my form will be called like the new variable. 如果值更改,则将像新变量一样调用表单中的标签。

Now I want to do this without a timer, so the app should recognize if the value changed by itself. 现在,我想在没有计时器的情况下执行此操作,因此应用程序应识别该值是否已自行更改。 Is this maybe possible with the using of properties? 使用属性是否可能做到这一点?

This is my current code: 这是我当前的代码:

private void timer1_Tick(object sender, EventArgs e)
    {
        Dictionary<string, string> humechDictionary = sqlClientHumech.Select("control");
        System.Diagnostics.Debug.WriteLine(humechDictionary);
        var countTest = sqlClientHumech.Count("control");
        System.Diagnostics.Debug.WriteLine(countTest);
        foreach (KeyValuePair<string, string> kvp in humechDictionary)
        {
            System.Diagnostics.Debug.WriteLine("Key = {0}, Value = {1}",
                kvp.Key, kvp.Value);
        }
        var modusValue = humechDictionary["modus"];
        System.Diagnostics.Debug.WriteLine(modusValue);
        if (modusValue == "excel")
        {
            label1.Text = "EXCEL";
        }
        else if (modusValue == "kinect")
        {
            label1.Text = "KINECT";
        }
        else if (modusValue == "manuell")
        {
            label1.Text = "MANUELL";
        }
    }

No, this kind of push notification outbound from the server is not possible with vanilla MySQL. 不,使用香草MySQL无法从服务器发出此类推送通知 If you're looking for a change in a column value in a DBMS, you need to poll it, as you have been doing. 如果要在DBMS中查找列值的更改,则需要像往常一样进行轮询。

You could create a user-defined function and call it from a trigger. 您可以创建一个用户定义的函数并从触发器中调用它。 But this is a perilous approach for lots of reasons. 但是,出于多种原因,这是一种危险的方法。

Here's a decent discussion of the issue. 这是关于这个问题的一个体面的讨论。 http://karwin.blogspot.com/2006/10/catch-22-of-active-database.html http://karwin.blogspot.com/2006/10/catch-22-of-active-database.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM