How to Connect to Any of the Specified MySQL Hosts. C# MySQL

Unable to connect to any of the specified MySQL hosts when connecting to MySQL database via SSH.NET tunnel in C#

You are connecting via an SSH tunnel.

So your primary problem is that the Host in the connection string must be localhost (the local end of the SSH tunnel), not dbserver. Or even better, use ForwardedPort.boundHost (and ForwardedPort.boundPort).


The second problem is that you cannot use ForwardedPortDynamic, but ForwardedPortLocal.



var forwardedPort = new ForwardedPortLocal("127.0.0.1", "127.0.0.1", 3306);

client.AddForwardedPort(forwardedPort);
forwardedPort.Start();

string connStr =
string.Format(
"Server = {0};Port = {1};Database = dbname;Uid = dbuserid;Pwd = dbpwd;",
forwardedPort.BoundHost, forwardedPort.BoundPort);

See also Connection to MySQL from .NET using SSH.NET Library.


If your database does not run on the webserver, but on dbhost, you have to use that in the ForwardedPortLocal constructor:

var forwardedPort = new ForwardedPortLocal("127.0.0.1", "dbhost", 3306);

Unable to connect to any of the specified MySQL Hosts? C# + Heroku + ClearDB

I suspect you're running into this known bug in Oracle's MySQL Connector/NET: bug 97448. (I can't resolve the domain name you gave in the question, but if it resolves to more than one A record then that will trigger the bug.)

The fix is to uninstall the MySql.Data NuGet package and install MySqlConnector instead: https://www.nuget.org/packages/MySqlConnector/

This supports the same API as MySql.Data, so it should be a drop-in replacement.

Unable to connect to any of the specified mysql hosts.' error

I solved the issue by replacing Xamarin.MySql.Data with MySqlConnector.
It seems Xamarin.Mysql.Data is outdated or something.



Related Topics



Leave a reply



Submit