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
How to Format Timespan in Xaml
Exporting Datagridview to CSV File
File Write Permission Issue Under "Program Files" Folder
Writing to Then Reading from a Memorystream
How to Split a Number into Individual Digits in C#
Select Either a File or Folder from the Same Dialog in .Net
How to Check for Nulls in a Deep Lambda Expression
How to Change Listview Selected Row Backcolor Even When Focus on Another Control
Why Won't Anyone Accept Public Fields in C#
How to Determine If an Event Is Already Subscribed
Entity Framework 4: How to Find the Primary Key
Encrypting/Decrypting Large Files (.Net)
Simple Way to Display Row Numbers on Wpf Datagrid