My ISP recently installed Cloud Linux on their web servers. After that, I'm seeing an odd behavior connecting to my MySQL database from C#. Specifically, the first connection attempt in each scheduled task returns "Unable to connect to any of the specified MySQL hosts." I put the connection attempt in a retry loop in a method:
public static bool OpenConnection(MySqlConnection connection)
{
bool result = false;
int retry = 0;
do
{
try
{
connection.Open();
result = true;
}
catch (Exception openexc)
{
retry++;
Emailer.EmailError(string.Format("OpenConnection {0}", retry), openexc);
Thread.Sleep(1000);
}
} while (!result && retry < 5);
return result;
}
The odd thing is that 99% of the time I get this error message, the second attempt to connect succeeds. Has anyone seen this type of behavior or notice anything out of the ordinary about this connection opening method?
Note that this is from a rewrite of some scheduled tasks that were previously written in VB6. The VB6 version quit working because of errors connecting to the server. Rather than maintain the VB6 code, I decided to translate to C#. I only bring this up because the errors started to happen in VB as well in what was working (but not very robust) code.
- Brett