问题
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