I've been trying the following code to attempt to connect to a remote database I'm hosting on digital ocean.
MySqlConnection myConnection = new MySqlConnection("Server = 104.236.197.146; Port = 3306; Database = BattleRoyale; Uid = root; Pwd = password");
try
{
myConnection.Open();
}
catch (Exception e)
{
MessageBox.Show( e.ToString(), "Database connection error" , MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Whenever I attemt to run this code I get the following error:
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySql hosts.
I believe the problem is with the hosted database. I've tried the following things:
GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY 'rootPass';
I've been trying to check to see if TCP/IP is enabled, but I cannot find it via phpMyAdmin nor going through putty or anything.
As you can tell, I don't know much about Linux machines and I'm just trying to connect to this database to work on a school project. Who knows what I've done trying to fix this issue. Any help would be greatly appreciated.
Possible reasons include:
Most probably it's 1. or 2. Especially 1. is something you don't think of at first.
Please note that many hosters don't allow access to the databases from outside their own network. That's why often PhpMySQL works but remote connections don't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.