0

I'm creating a C# (.NET 4.0) application which uses MySQL database to store data. This database is installed on a 3rd party company's server and the application has to connect remotely - currently by a domain name (myname.home.pl).

In addition there is a website which also uses the same database, this website is located on the same server so it connects to DB by localhost.

The website always is working properly and there are no problems with a connection.

The C# application usually also connects successfully but SOMETIMES it can't open a connection and after the connection timeout it returns an error: "Unable to connect to any of the specified MySQL hosts". I have no idea what could be a reason of such error.

This problem occurs on Windows XP and Windows 7, other OS versions were not tested.

Connection String is in following format (sqlData struct contains login data):

connection.ConnectionString = String.Format(
    "server={0};database={1};user='{2}';password='{3}';",
    sqlData.Server,
    sqlData.Catalog,
    sqlData.User,
    sqlData.Password
);

I've found several topics about this error on stackoverflow but rather not resolved...

Did anyone have similar problem? What can be its reason or how can I make it not to occur?

Thanks in advice for any help.

  • You should check/post everything about that exception (error code, any other inner exception) and check server side log. Like this...is shotting in the fog. In general if you go through Internet you should also setup a try/retry pattern (maybe 1st try with a shorter timeout). – Adriano Repetti Jul 21 '14 at 12:15
  • Liekly network related – Tsukasa Jul 21 '14 at 12:15
  • exc.ToString() gave me only the information: MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() – user3860515 Jul 26 '14 at 09:55

1 Answers1

-2

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.

   em MySql.Data.MySqlClient.NativeDriver.Open()

   em MySql.Data.MySqlClient.Driver.Open()

   em MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)

   em MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()

   em MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()

   em MySql.Data.MySqlClient.MySqlPool.GetConnection()

   em MySql.Data.MySqlClient.MySqlConnection.Open()

   em EasylockControl.Login.button1_Click(Object sender, EventArgs e)

   em System.Windows.Forms.Control.OnClick(EventArgs e)

   em System.Windows.Forms.Button.OnClick(EventArgs e)

   em System.Windows.Forms.Button.PerformClick()

   em System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)

   em System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)

   em System.Windows.Forms.Control.PreProcessMessage(Message& msg)

   em System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)

   em System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93
kerepk
  • 1