0

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);
        }

    }
DMcDonald
  • 89
  • 1
  • 14
  • What happens after the 15 seconds? Do you connect or get an exception? Is MySQL running at all? Is the port correct? The firewall doesn't apply to localhost addresses. – Panagiotis Kanavos Apr 15 '16 at 15:30
  • Hi @Panagiotis Kanavos It connects and I get the response back from MySQL as it's supposed to saying 'connected' then 'disconnected'. It just takes a long time. MySQL is definitely running. The port is correct I've checked all these things an uncountable number of times. If the firewall doesn't affect localhost then is there anything else that could slow it down? I want to know what route it takes so I can check everything – DMcDonald Apr 15 '16 at 15:55
  • Do you have multiple server versions running in the same machine? – CST RAIZE Apr 15 '16 at 17:19
  • No I've only ever installed MySQL5.7 on this machine. – DMcDonald Apr 15 '16 at 18:18
  • 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. – DMcDonald Apr 15 '16 at 18:21
  • The first thing I'd check is memory and swap file usage, especially since everything is evidently running on the same machine. – Dave Apr 15 '16 at 18:23
  • Hi Dave thanks for your input, I've run the code and monitored CPU, memory and swap file usage and haven't detected a spike in any of those resources. – DMcDonald Apr 15 '16 at 18:39

0 Answers0