Connecting with remote mysql database, getting the error "Unable to connect to any of the specified MySQL hosts"

16,435

Solution 1

Your connection string seems wrong. Try:

MySqlConnection c = new MySqlConnection("server=64.191.12.54; database=alyataco_test4application; uid=xxxxxxxx; pwd=xxxxxxxx");

See http://www.connectionstrings.com/mysql for more connection string exemples.

Solution 2

Chances are your host does not allow remote connections to the database server. Easy way to tell is if you deploy your project to the server and it works.

Share:
16,435
R.Vector
Author by

R.Vector

Hi guys , my name is ryan , i am studying computer science , i am working with C# and SQL at the moment .

Updated on June 07, 2022

Comments

  • R.Vector
    R.Vector almost 2 years

    I am making an application that connects to remote mysql database into some cpanel account. I created the database on the cpanel account and defined a username and password for it. I am using MysqlConnector. So far I have written the following code:

    using MySql.Data.MySqlClient;
            MySqlConnection c = new MySqlConnection("SERVER = 64.191.12.54; DATABASE = alyataco_test4application; User ID = xxxxxxxx; PASSWORD = xxxxxxxx");
            c.Open();
    

    but i got error :

    MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.
    

    i also saw Connect to remote MySQL database with Visual C# but didn`t help too