Below is a screenshot from MySQL workbench. The parameters are not real, but the structure shown here is exactly as per my real connection which is working nicely.
I am trying to connect to this database using a .NET C# project.
I have downloaded and referenced the project https://sshnet.codeplex.com/
I seem to be having success with actually connecting to the SSH server:
using (SshClient objSSHClient = new SshClient("199.199.199.199", "root", "<the SSH user password>"))
{
objSSHClient.Connect();
MessageBox.Show("objSSHClient.IsConnected=" + objSSHClient.IsConnected.ToString());
objSSHClient.Disconnect();
}
Great. So, now my current understanding is that I need port forwarding setup so I can tunnel my MySQL connection through the SSH client connection.
It all goes badly from here on in. I think I've got either the port forwarding and/or the connection string settings mixed up.
When referencing other similar questions I could't find a situation which seems to have the SSH Hostname as a different value to the MySQL hostname which is the situation I have.
Here's my latest attempt at trying to connect:
using (SshClient objSSHClient = new SshClient("199.199.199.199", "root", "<the SSH user password>"))
{
ForwardedPortLocal objPortForward = new ForwardedPortLocal("127.0.0.1",3306, "mySQLDatabase.databaseserver.com", 3306);
objSSHClient.AddForwardedPort(objPortForward);
objSSHClient.Connect();
using (MySqlConnection objDBCon = new MySqlConnection())
{
objDBCon.ConnectionString = "Server=127.0.0.1;Database=<the database name>;Uid=databaseuser;Pwd=<the database user password>;";
objDBCon.Open();
}
objSSHClient.Disconnect();
}
Which always fails on the .Open() method... "Unable to connect to any of the specified MySQL hosts."