Accessing a remote MySQL database over SSH in .NET???

Posted on 2007-08-08
Last Modified: 2013-11-05

I am trying to access a remote MySQL database in ASP.NET. Normally, to access the database, i manually SSH to the server and then login to MySQL. However, i am not sure how to do that through code.

It would be nice if i could just create a connection string like:

 Dim myConnectionString As String = _
                            "server=192.168.xx.xxxx;" & _
                            "Database=TestDB;" & _
                            "User ID=username1;" & _

But that won't work because i haven't first created an SSH connection. Is there a way to create an SSH connection in .NET before connecting to a remote database?.


Question by:Allston44
    LVL 50

    Expert Comment

    by:Steve Bink
    You should not need to create an SSH connection.  SSH stands for "secure shell", and is a method to gain remote command line access.  Your server should be running mysql on port 3306, which means you can hit it directly instead of shelling in and using the command line.

    Here's one code example of how it is done:
    LVL 17

    Expert Comment

    Did you mean SSL connection? If yes, then you are right, there is a way to access MySQL securely by using a SSH tunneling component.

    Some sample links:

    Author Comment

    thanks routinet, in general i have no trouble connecting to al MySQL database. The trouble has been connecting to this database remotely (even when using the method you described above). For whatever reason, i can only connect to it when i go through SSH (i didn't realize it was just for command line) Could it be that the hosting service is blocking remote access to port 3306?

    leannonn, one of those products looks promising, but i'd prefer to avoid paying for a compononet. I will reconsider as a last option...


    LVL 17

    Expert Comment

    > Could it be that the hosting service is blocking remote access to port 3306?

    Yes, definitely. Many of them close the port from `security reasons`, as they say :(
    LVL 50

    Accepted Solution

    > Could it be that the hosting service is blocking remote access to port 3306?

    As leannonn indicated, some hosts close all ports, and open only the ones you request.   You should check with them to make sure this is not an issue.

    Another common problem is not adding the correct user@host information into MySQL.  Have you verified that the ASP server's information has been given the proper permissions to access the db?  Check here for more info:

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now