Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 738
R.Vector Avatar asked Feb 04 '26 04:02

R.Vector


2 Answers

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.

like image 71
Mathieu Avatar answered Feb 05 '26 18:02

Mathieu


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.

like image 26
doogle Avatar answered Feb 05 '26 16:02

doogle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!