I am using as stated in subject version 2014.4.6-beta1 from NuGet and after following few posts I try to forward application connection to MySQL over ssh. This works just wing with plink (putty)
On local machine nest at shows that there is socket listening on 127.0.0.1 port 3306. While this port is open I did try to use other commercial client to connect to remove database using 127.0.0.1:3306. Only delegate is firing is HostKeyReceived with "ssh-rsa" And CanTrust = true
Here is my code
public void ConnectDatabase(string host, UInt16 port, string user, string password)
{
I get exception on _sqlConnection.Open();
{"Unable to connect to any of the specified MySQL hosts."}
On local machine nest at shows that there is socket listening on 127.0.0.1 port 3306. While this port is open I did try to use other commercial client to connect to remove database using 127.0.0.1:3306. Only delegate is firing is HostKeyReceived with "ssh-rsa" And CanTrust = true
Here is my code
public bool ConnectSSH(string host, UInt16 port, string user, string password)
{
if (_sshTunnel != null)
return false;
_sshTunnel = new SshClient(host, port, user, password);
_sshTunnel.ErrorOccurred += delegate(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
{
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.ERROR, "Tunnel Error: " + e.Exception.Message));
};
_sshTunnel.HostKeyReceived += delegate(object sender, Renci.SshNet.Common.HostKeyEventArgs e)
{
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.ERROR, "Tunnel Key: " + e.HostKeyName));
};
_sshTunnel.Connect();
if (_sshTunnel.IsConnected)
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.INFO, "Tunnel up"));
else
{
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.INFO, "Tunnel down"));
return false;
}
var forwardPort = new ForwardedPortLocal("127.0.0.1", 3306, "127.0.0.1", 3306);
_sshTunnel.AddForwardedPort(forwardPort);
forwardPort.Exception += delegate(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
{
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.ERROR, "Tunnel Error: " + e.Exception.Message));
};
forwardPort.RequestReceived += delegate(object sender, Renci.SshNet.Common.PortForwardEventArgs e)
{
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.ERROR, "Tunnel Echo: " + e.OriginatorHost + ":" + e.OriginatorPort));
};
forwardPort.Start();
if (forwardPort.IsStarted)
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.INFO, "Forward up"));
else
{
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.INFO, "Forward down"));
_sshTunnel.Disconnect();
_sshTunnel.Dispose();
_sshTunnel = null;
return false;
}
return true;
}
Database connection using MySQL dotnet connector version 6.8.3.0public void ConnectDatabase(string host, UInt16 port, string user, string password)
{
Disconnect();
_sqlConnection = new MySqlConnection();
if (_compression)
_sqlConnection.ConnectionString = String.Format("Server={0};port={1};User={2}; Password ={3}; Pooling=true; UseCompression=true",
host, port.ToString(), user, password);
else
sqlConnection.ConnectionString = String.Format("Server={0};port={1};User={2}; Password={3}; Pooling=true; UseCompression=false",
host, port.ToString(), user, password);
_sqlConnection.Open();
OnLogMessageEvent(this, new LogEventArg(LogEventArg.eType.INFO, "Connected established"));
}I get exception on _sqlConnection.Open();
{"Unable to connect to any of the specified MySQL hosts."}