I'm trying to connect to a MySQL database in C #, and my code has been working perfectly since I started, but sometimes I know it's giving me this error like, every 2 days, sometimes it connects sometimes not , I have 2 DB in different servers and when I try to connect to the second server it always works, what happens?
this is the error
An exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll but was not handled in the user code
Additional information: can not connect to any of the specified MySQL hosts.
This is my code
MySqlConnectionStringBuilder conn_string = new MySqlConnectionStringBuilder();
conn_string.Server = Conexion.Server;
conn_string.Port = Conexion.PORT;
conn_string.UserID = Conexion.UID;
conn_string.Password = Conexion.PASSWORD;
conn_string.Database = Conexion.Database;
MySqlConnection SqlCon = new MySqlConnection(conn_string.ToString());
SqlCon.Open();
if (SqlCon.State == ConnectionState.Open)
{
toolStripStatusLabel_Con.Text = "Conectado";
toolStripStatusLabel_Con.ForeColor = System.Drawing.Color.Green;
SqlCon.Close();
}
else
{
toolStripStatusLabel_Con.Text = "Desconectado";
toolStripStatusLabel_Con.ForeColor = System.Drawing.Color.Red;
SqlCon.Close();
}