gpt4 book ai didi

c# - :'Unable to connect to any of the specified MySQL hosts.' 错误

转载 作者:行者123 更新时间:2023-11-30 21:28:34 25 4
gpt4 key购买 nike

我想使用连接字符串连接到 MySQl 数据库,但无法连接我正在使用 UWP 并将秋季创建者版本用于目标版本和最小版本

我已经为 Mysql 连接器安装了 Nuget 包我试过更改带和不带端口等的字符串。

public string GetMatchCode()
{
string connectString = "Server=###.###.###.###;Database=Db;Uid=root;Pwd=123;sslmode=none;port=3306";
string sql = "SELECT * FROM `customer`";
using (var connect = new MySqlConnection(connectString))
using (var command = new MySqlCommand(sql, connect))
{
connect.Open();
return command.ExecuteScalar().ToString();
}
}

MySql.Data.MySqlClient.MySqlException: 'Unable to connect to any of the specified MySQL hosts.' MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The error starts at connect.Open();

我已经测试了与 Workbench 的连接以确保其正常工作。我浏览了大多数类似的帖子,但没有一个对我有用。

最佳答案

连接失败的情况有很多种。请参阅以下几点来解决您的错误。

  1. Check your Windows Firewall to ensure that server has an access to Port's associated with your MySql.
  2. Disconnect and re-connect your VPN client.
  3. Follow standard Spacing and Order of parameters in connection string. Follow below format to build/form connection string. Server=ServerAddress; Port=4563; Database=DataBaseName; Uid=UserName;
    Pwd=Password;
  4. Consider using Connection Pulling, So existing connection will be reused.

关于c# - :'Unable to connect to any of the specified MySQL hosts.' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57520794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com