(1)c#连接Mysql数据建立连接时提示:Unable to connect to any of the specified MySQL hosts.

(2)原因:数据库的服务器IP地址填写有错误

(3)案例:       

例如:

这种连接才是正确的

public static string connectionString = "Database=test;Data Source=test;Port=3306;UserId=root;Password=root;Charset=utf8;TreatTinyAsBoolean=false;Allow User Variables=True";

而自己却这样连接

public static string connectionString = "Database=test;Data Source=tests;Port=3306;UserId=root;Password=root;Charset=utf8;TreatTinyAsBoolean=false;Allow User Variables=True";

第二个很明显,IP地址就会有错误,就会出现Unable to connect to any of the specified MySQL hosts.错误了

(4)解决方法,就是对应服务器的连接方式,例如改为

public static string connectionString = "Database=test;Data Source=test;Port=3306;UserId=root;Password=root;Charset=utf8;TreatTinyAsBoolean=false;Allow User Variables=True";

的连接方式就可以解决Unable to connect to any of the specified MySQL hosts.错误了。

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐