Sign in to follow this  

[.net] C#/MySQL connection issue

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;
result = true;
catch (Exception openexc)
Emailer.EmailError(string.Format("OpenConnection {0}", retry), openexc);
} 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this