如何从另一台PC在线连接到MySQL数据库? VB.NET [英] How to connect to MySQL database from another PC online? VB.NET

查看:158
本文介绍了如何从另一台PC在线连接到MySQL数据库? VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的连接字符串

mySqlCon.ConnectionString = "server=testserver.noip.me; port=3306; database=testserver1; uid=admin; pwd=admin"

我用 TryCatch 函数创建了一个vb.net应用程序,用于检查MySql连接.

I have created a vb.net application with TryCatch function to check MySql connection.

我的服务器 testserver.noip.me是我的公共ip 的主机名(该主机名是一个示例,如果您在线检查端口,它将无法正常工作) .如果将服务器更改为 localhost/127.0.0.1 或我的私有ip 地址(例如 192.168.0.xx ),则结果为连接就好了.甚至可以在同一wifi网络内的另一台PC上连接到数据库.

My server testserver.noip.me is a hostname of my public ip (The hostname is an example, if you check the port online, it wont work). If I change the server to localhost/127.0.0.1 or my private ip address which is something like 192.168.0.xx, the result is connected just fine. Able to connect to database even on another PC but within the same wifi network.

每当我将其更改为公共IP地址或主机名时,应用程序都会返回错误消息:

Whenever I change it to my public ip address or my hostname, the application returns an error message :

无法连接到任何指定的MySQL主机."

"Unable to connect to any of the specified MySQL hosts."

这是代码

Try
        mySqlCon.Open()

        If mySqlCon.State = ConnectionState.Open Then
            Label5.Text = "Online"
            Label5.ForeColor = Color.GreenYellow
            LoginBtn.Enabled = True
        Else
            Label5.Text = "Offline"
            Label5.ForeColor = Color.LightPink
            LoginBtn.BackColor = Color.Red
        End If

        mySqlCon.Close()
    Catch ex As MySqlException
        If mySqlCon.State = ConnectionState.Open Then
            mySqlCon.Close()
        End If
Finally
        mySqlCon.Dispose()
    End Try

我也在路由器中完成了端口转发,结果还不错:

主机名端口3306检查也已打开:

其他信息:我已经安装了connectornet,并且正在为此使用MySQL工作台.

一切都可以在本地网络上正常运行,但不能在线运行.知道我应该怎么做才能使应用程序从另一个在线网络成功连接到数据库吗?请没有SSH或任何安全的连接指南,因为这只是一个测试服务器.

Everything is working fine on local network but not online. Any idea what I should do to make the application connect to the database successfully from another network online? No SSH or any secure connection guide please because this is just a test server.

推荐答案

在MYSQL(源计算机)中,您必须启用目标域名的访问权限. 在主机表中添加目标IP.

In your MYSQL (source machine) you have to enable the destination domain name for access rights. In the host table add your destination IP.

这篇关于如何从另一台PC在线连接到MySQL数据库? VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆