I was given a link to use this library to connect through an SSH connection to a MySQL database with C #.
Here is the LINK to the library, as many of you will find it interesting, since you do not need to open the SSH channel manually.
This is a very detailed library and has many features, but what I want to do is pretty simple. I just want to open the SSH channel every time I want to write to the database.
While I was looking for the source that was provided, I went over to this part of the code, which can be found in TestSshCommand.cs , and I think I can use this part for my connections, but I need your help to make it work, since I have a connection string. I do not know how to put it all together.
the code:
public void Test_Execute_SingleCommand()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var result = ExecuteTestCommand(client);
client.Disconnect();
Assert.IsTrue(result);
}
My code for connecting to a channel without SSH:
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con2"].ConnectionString;
con.Open();
cmd = new MySqlCommand("SELECT COUNT(*) FROM " + ConfigSettings.ReadSetting("main"), con);
So, how can I combine this code with the above so that it can open the SSH channel first and then fulfill my request?
Do I need to embed my code inside to connect and disconnect functions?
: .dll , , . -, , , , ( ) ?
EDIT:
, . SSH , .
, . , , - , , mysql
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);
cmd.ExecuteNonQuery();
client.Disconnect();
}