• Advertisement
Sign in to follow this  

[.net] C#/MySQL connection issue

This topic is 2382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement