Reputation: 5805
I want to connect trough SSH channel to mysql database on the server.
I have downloaded this SSH.Net library.
This is what I have tried and I thought it will work after my secured connection has been established.
My SSH connection is established but normal connection to database is not executed.
So check my code please:
using (var client = new SshClient("cpanel****", "******", "******"))
{
client.Connect();
con = new MySqlConnection(GetConnectionString());
con.Open();
cmd = new MySqlCommand(String.Format("insert into {0} values (null, ?Parname , ?Parname2, ?Parname3, ?Parname4, ?Parname5, ?Parname6, ?Parname7);", ConfigSettings.ReadSetting("main")), con);
cmd.Parameters.Add("?Parname", MySqlDbType.Double).Value = Math.Round(deciLat, 5);
// ... more parameters
cmd.ExecuteNonQuery();
client.Disconnect();
}
Upvotes: 0
Views: 1415
Reputation: 34527
Here is a tutorial http://georgelantz.com/2007/09/10/access-mysql-through-ssh-tunnel-in-a-windows-net-application/ which sounds reasonable.
Basic idea is to establish an SSH connection with a tunnel (aka port forwarding) and then point your MySQL connection to localhost.
SSH tunnel redirects connections to localhost:XX to the ssh server port:YY. So your port YY will be the mysql connection port, and in your connection string you would use localhost:XX.
The SSH library you are using also seems to support port forwarding, so you might be able to get that working as well.
Upvotes: 1