简体   繁体   中英

“Unable to connect to any of the specified MySQL hosts” in UWP app (C#)

I'm trying to connect a UWP app written in C# to a MySQL DB hosted on another machine on the local network (it's on a Raspberry Pi, but I doubt that makes a difference). The code I have right now is:

string M_str_sqlcon = "Server=192.168.0.101;Port=3306;Database=****;User ID=****;Password=****;";
MySqlConnection mysqlcon = new MySqlConnection(M_str_sqlcon);
MySqlCommand mysqlcom = new MySqlCommand("select * from mysql.users", mysqlcon);
mysqlcon.Open();

However, the code fails with a 'Unable to connect to any of the specified MySQL hosts.' error. Here's the pic of the error pop-up.

错误消息。

I've tried changing the server address, and if I enter one that isn't present on the local network, it fails with a different error (along the lines of Unable to connect to any of the specified MySQL hosts, cannot reach target server).

I've tried various connection strings I've found around StackOverflow, and in MS' own docs, but nothing seems to help.

I can properly ping the DB IP from the machine I'm developing this app on, and I can access the database normally using MySQL Workbench, so I'm sure it isn't a problem with the user permissions/settings.

Any help would be appreciated!

Try to connect with the database using some GUI tools. If it works you will be sure that there is a problem with your application. It could be network problems etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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