T
T
trace82016-06-09 12:02:25
MySQL
trace8, 2016-06-09 12:02:25

How to connect to db from c# via ssh?

Hello! How to connect from c# to Mysql, which is running on a server that can only be accessed via SSH? It's just that I can connect through PuTTY, I can make requests and receive signs. Should I use the
Tamir.SharpSsh library? it turns out from the program code to send requests and receive answers, but the format of the answer does not get tired. It would be nice to receive in the form of a DataTable. Screenshot of the table format, if you use the Tamir.SharpSsh lib: f1dbeb5e8f954a7a9790cd142944ceb2.png
All code is written in the format (this is how everything worked until we moved from localhost to a remote server):

DataTable dt = new DataTable();
        MySqlConnectionStringBuilder mysqlCSB;
        mysqlCSB = new MySqlConnectionStringBuilder();
        mysqlCSB.Server =  "адрес сервера";
        mysqlCSB.Database = "имя бдшки";
        mysqlCSB.UserID = user;
        mysqlCSB.Password = pass;
        mysqlCSB.Port = 3306;

        string queryString = @"SELECT * FROM articles;"; 
                                  
          
        using (MySqlConnection con = new MySqlConnection())
        {
            con.ConnectionString = mysqlCSB.ConnectionString;
            MySqlCommand com = new MySqlCommand(queryString, con);
            try
            {
                con.Open();
                using (MySqlDataReader dr = com.ExecuteReader())
                {
                    if (dr.HasRows)
                    {
                        dt.Load(dr);
                        Console.WriteLine("ok");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

Maybe you can suggest a solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
chupasaurus, 2016-06-09
@chupasaurus

man ssh /-R.
Well, there is no normal implementation of openssh under C#.

M
Michael, 2016-06-09
@Madfisht3

Make an ssh tunnel manually and work directly with the base.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question