无法连接到Web托管的MySQL数据库

时间:2018-01-17 22:58:52

标签: mysql vb.net

我正在使用VB.NET连接到MySQL数据库。

我有以下代码:

Public Function getListOfDatabase() As List(Of String)
    Dim SQL As String = "select * from covenusers"

    Dim output As New List(Of String)()

    ' Set the connection string in the Solutions Explorer/Properties/Settings object (double-click)

    Using cn = New MySqlConnection("Server=server33.web-
hosting.com;Port=3306;Database=dbname;Uid=dbusername;
Pwd=password123;")
        Using cmd = New MySqlCommand(SQL, cn)

            cn.Open() 'this is where it breaks

            ' do stuff
        End Using
    End Using

    Return output

End Function

我正在使用Imports MySql.Data.MySqlClient进行MySQL处理。我得到例外:Unable to connect to any of the specified MySQL hosts.

我知道我的服务器地址,用户名,数据库名称和密码都是正确的。我到底在这里连接到底是什么?它是通过SSH还是其他什么?

1 个答案:

答案 0 :(得分:0)

显然,共享主机不允许您直接连接到MySQL数据库。我不得不使用Renci.SSHClient(google it)建立一个SSHClient并通过它转发我的数据库。多么痛苦

希望这可以帮助有同样问题的人。