Advertisement Jump to content
Sign in to follow this  

[.net] C#/MySQL connection issue

This topic is 2718 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;
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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!