0

I am creating connection with my online mysql database but it gives me the error (unable to connect to any of the specified Mysql hosts).

this is my code:

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        MySqlConnection con1 = new MySqlConnection("Server=http://eu5org.freewebhostingarea.com; Port=3306; Database=477928; Uid=477928; Pwd=password123;");
        con1.Open();
        MessageBox.Show("Connection Established");                
        con1.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
} 

how could i correct this?

daniele3004
  • 13,072
  • 12
  • 67
  • 75
Loyal
  • 773
  • 2
  • 8
  • 20
  • possible duplicate of [Unable to connect to any of the specified MySQL hosts when checking connection](http://stackoverflow.com/questions/22962923/unable-to-connect-to-any-of-the-specified-mysql-hosts-when-checking-connection) – MUG4N Nov 30 '14 at 09:13
  • i have established the connection locally. but when connecting to online database it gives me the error. – Loyal Nov 30 '14 at 09:18
  • remove `http://` from the connection string – Fred Nov 30 '14 at 09:20
  • Are you sure you have the right address for the server? It is usually different from the admin login panel – Fred Nov 30 '14 at 09:23
  • Just looked at the FAQ for the address in your connection string and saw this.. Q: What is database host? A: Only localhost. External access is not allowed. – Fred Nov 30 '14 at 09:25
  • when i open my online database the above address comes in the URL. – Loyal Nov 30 '14 at 09:26

1 Answers1

0

It seems that the hosting you have only allows a server address of localhost any other address will fail.

Fred
  • 5,663
  • 4
  • 45
  • 74
  • so i can not access it? – Loyal Nov 30 '14 at 09:30
  • No, not unless the application or website is on the same server as the database. The only address the hosting company allows for the database connection is `localhost` ie same machine. – Fred Nov 30 '14 at 09:32
  • You may be able to change this by logging in to your hosting control panel. – Resource Nov 30 '14 at 10:14
  • @user910683 As I have told the OP the hosting company states in their FAQ only localhost connections are allowed. – Fred Nov 30 '14 at 10:24