Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8031565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:08:36+00:00 2026-06-05T01:08:36+00:00

I was given a link to use this library for connection through SSH connection

  • 0

I was given a link to use this library for connection through SSH connection to a MySQL database with C#.

Here is the LINK to the library as a lot of you will find this interesting as you don’t need to open a SSH channel manually.

This is a very detailed library and has a lot of features but what I want to do is pretty simple. I just want to open a SSH channel each time I want to write to the database.

While I was searching through the source that is provided I came up 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 get it work as I have my connection string I don’t know how to connect all of it.

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 connectiong to non SSH channel is:

con.ConnectionString = ConfigurationManager.ConnectionStrings["Con2"].ConnectionString;
            con.Open();
            cmd = new MySqlCommand("SELECT COUNT(*) FROM " + ConfigSettings.ReadSetting("main"), con);

     //...... more of the code

So how can I combine this code to the above one so it can first open a SSH channel and then execute my query?

Do I need to put my code inside connect and disconnect functions?

One more think I have add .dll file inside references and I must say that none of the imports are working. So can someone please download the library and try this simple code to see if references are working on your project and so that everyone ( which are a lot ) can have a working solution for their future projects?

EDIT:

This is my code that I was trying to do later on. My SSH connection works now only need to combine those two to get it work.

Problem is that I need to have one database locally on my pc and need to connect to the server. So port forwarding won’t work as somone says on the forum that I can’t port forward while mysql already have port for running

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();
           }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:08:38+00:00Added an answer on June 5, 2026 at 1:08 am

    You will need to setup port forwarding with your SSH connection…

    Basically make a SSH connection that listens on port 3306 on localhost and forwards that to your MySQL DB server…

    In the connections string to your MySQL DB you need to change the part server=... to server=localhost while your SSH connection needs to go to your MySQL DB server’s IP.

    IF you can’t forward port 3306 you can use any port you want BUT you need change the additionally the port= part of the connection string… see here for examples on connection strings with a different port… the SSH connection still targets 3306 but listens on a different port on localhost in this case…

    Here are some working examples with source code (although not with SSH.NET since I don’t use SSH.NET but this should nonetheless get you started IMO):

    • http://georgelantz.com/2007/09/10/access-mysql-through-ssh-tunnel-in-a-windows-net-application/
    • http://www.howtogeek.com/howto/ubuntu/access-your-mysql-server-remotely-over-ssh/ (this is just an option on how to use a local SSH client from commandline to set this up)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I pasted the code given in this link to a file called md5.js. http://www.webtoolkit.info/javascript-md5.html
I am developing an UI(Home screen) just like this screen given in this link
I am in process of getting all hierarchical links from a given link and
How can you retrieve the value of the rel attribute of a given link
If no og:image or link rel=image_src is given, Facebook tries to guess the thumbnail
What is the best way to link to the icons of websites? Meaning, given
I use the hsparql library to run a query that returns german text; and
Twitter Bootstrap http://twitter.github.com/bootstrap/javascript.html#dropdown has a dropdown.js library (at http://twitter.github.com/bootstrap/1.4.0/bootstrap-dropdown.js )that will change the dropdown
I'm trying to use the Chilkat encryption library in SQL Server 2008 via a
Hi i need send file to server i use this code public void PostFile()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.