简体   繁体   English

从VB.NET连接到mysql数据库

[英]Connecting to mysql database from VB.NET

I'm having some trouble setting up a working connection to a mysql database from Visual Studio 2010. After downloading and installing the mysql-net connector, I set up a simple testing database in Xampp and experimented around a bit until I managed to read some values from the database and inserting new ones. 我在从Visual Studio 2010建立到mysql数据库的工作连接时遇到了一些麻烦。下载并安装了mysql-net连接器后,我在Xampp中建立了一个简单的测试数据库,并进行了一些试验,直到设法读取一些内容数据库中的值并插入新值。

Now I'm trying to access another database on a remote server and all I get is an error message: 现在,我正在尝试访问远程服务器上的另一个数据库,而我得到的只是一条错误消息:

Unable to connect to any of the specified MySQL hosts. 无法连接到任何指定的MySQL主机。

Basically, I'm only trying to execute this code: 基本上,我只是尝试执行以下代码:

Dim con As New MySqlConnection("Server=111.11.111.111;Uid=root;Pwd=mypwd;Database=mydb;")
con.Open()
con.Close()

(server ip looks a bit different of course) (服务器ip当然看起来有些不同)

When I access my local database, it looks quite similar: 当我访问本地数据库时,它看起来非常相似:

Dim con As New MySqlConnection("Server=127.0.0.1;Uid=root;Pwd=;Database=test;")
con.Open()
con.Close()

Nevertheless, I can access the remote database easily using a simple PHP script... no problems there. 不过,我可以使用简单的PHP脚本轻松访问远程数据库...那里没有问题。

Any ideas how to fix this? 任何想法如何解决这一问题? :-/ :-/

From the documentation for MySql on connectionstrings.com , it looks like the default port is 3306. connectionstrings.com有关 MySql的文档中可以看到,默认端口为3306。

Make sure the firewalls on the machines and between them allow traffic through this port. 确保计算机上及其之间的防火墙允许通过此端口的通信。

Try to use connection string like this - 尝试使用这样的连接字符串-

Host=host_name;User Id=root;Port=3306;Database=test;Password=pwd

Specify values you need - host name, port, password... 指定所需的值-主机名,端口,密码...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM