I'm trying to connect to a remote mysql server using a SSH tunnel set up using OpenSSH key file and SSH.Net library as shown in the code section below...
try
{
PrivateKeyFile pkfile = new PrivateKeyFile("C:\\Users\\OpenSSHKey", "mypassword");
var client = new SshClient("servername.com", 22, "myusername", pkfile);
client.Connect();
if (client.IsConnected)
{
var local = new ForwardedPortLocal(22, "localhost", 3306);
client.AddForwardedPort(local);
try
{
local.Start();
}
catch (SocketException se)
{
}
string connStr = "server=localhost;user=mysql_username;database=database_name;port=3306;password=MyDBPassword;";
MySqlConnection sql = new MySqlConnection(connStr);
sql.Ping();
try
{
sql.Open();
}
catch (MySqlException se)
{
}
}
}
catch(Exception e)
{
}
the tunnel is definitely set up because it throws the following error "Unable to connect to any of the specified MySQL hosts" on the sql.Open() call...
Im sure the database is on the server named mysername because I can connect to it using putty or workbench with the credentials used in the MYSQL connection string... I hope someone can help