Any way to trace MySqlConnection to detect reasons for slow connection

眉间皱痕 提交于 2020-01-07 02:26:07

问题


I need to find some way in C# to trace the MySqlConnection.Open() methods connection to find out why it's taking over 15 seconds just to establish the connection. I.e to see some kind of connection log to find out whats holding it up.

The code below is in an otherwise empty project and I've tried disabling the firewall and changing the port.

Please help I've been trying to fix this for two days now and I'm almost admitting defeat.

EDIT: Also the port is 3310 instead of the 3306 mySQL default as i changed it to rule out port issues. EDIT: I've written and run the same program in Java using the JDBC connector and it ran almost instantly as it should so the problem seems to be .NET related.

 private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            string myConnection = "datasource=localhost;port=3310;username=root;password=root";
            MySqlConnection myConn = new MySqlConnection(myConnection);
            myConn.Open();
            MessageBox.Show("Connected");
            myConn.Close();
            MessageBox.Show("Disconnected");
        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }

    }

来源:https://stackoverflow.com/questions/36651150/any-way-to-trace-mysqlconnection-to-detect-reasons-for-slow-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!