I'm trying to connect MySQL Server 8.0 running on windows to C#. Before this, I was using PhpMyAdmin but now I've installed MySql 8.0 Command Line Client and I want to connect my program with it. It is running on port 2208 as port 3306 was already in use.
I've tried to search internet for solution but all the solution that appears are connecting MySQL with PhpMyAdmin.
server = "localhost:2208";
database = "LoginFormApplication";
uid = "root";
password = "";
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
Debug.WriteLine(connectionString);
connection = new MySqlConnection(connectionString);
OpenConnection(); //connecting to database
I'm looking to connect to MySQL server running on windows machine to C#. But it throws error even though the server is still running. Below are the errors:
1. Connection must be open and valid
2. Unable to connect to any of the specified MySQL hosts
3. Exception thrown: 'MySql.Data.MySqlClient.MySqlException' in MySql.Data.dll
4. Exception thrown: 'System.InvalidOperationException' in MySql.Data.dll
Open Connection Method:
connection.Open();
But there was a syntax error. I need to declare the port number separately in connection String. I was declaring the port number right after the I was declaring server name
Solution:
Server=myServerAddress; Port=1234; Database=myDataBase; Uid=myUsername;
Pwd=myPassword;
Link:
Unable to connect to any of the specified mysql hosts. C# MySQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With