Unable to connect to IONOS mySQL Database in C# app

45 views Asked by At

I am trying to open a connection to a mySQL Database hosted through IONOS. Using the database aside, at the moment I can't even get a connection going with the error

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

Currently I'm trying to established the connection through the Oracle MySql Nuget package.

using MySql.Data.MySqlClient;
etc.etc.

string server = "db5012345659.hosting-data.io";
string database = "dbs12345640";
string uid = "dbu5000002";
string password = "abc";

string connectionString = $"Server={server}; database={database}; UID={uid}; password={password};";
MySqlConnection connection = new MySqlConnection(connectionString);

connection.Open();

I have also tried using Microsofts SqlClient via


SqlConnectionStringBuilder test = new SqlConnectionStringBuilder()
{
DataSource = "db5012345659.hosting-data.io",
InitialCatalog = "dbs12345640",
UserID = "dbu5000002",
Password = "abc",
};

SqlConnection awd = new SqlConnection(test.ConnectionString);
awd.Open();

which also gives the error that it cannot establish a connection. I also opened port 3306 in the Firewall but that didn't change anything.

I was able to connect to the database and read/write values with a separate php script, so it seems to be accessible. I just need to do it in this C# application.

1

There are 1 answers

0
Dominik On

I had the same problem and tested the same connection methods. I had installed the latest mysql.data package 8.3.0

when I changed it to 8.0.3 it worked instantly my connection string looks like

Server=somehost;Database=somedatabase;Uid=someuser;PASSWORD=somepassword;