【问题标题】:Connecting with remote mysql database, getting the error "Unable to connect to any of the specified MySQL hosts"连接远程 mysql 数据库,收到错误“无法连接到任何指定的 MySQL 主机”
【发布时间】:2012-02-14 16:30:18
【问题描述】:

我正在制作一个连接到远程 mysql 数据库的应用程序到某个 cpanel 帐户中。我在 cpanel 帐户上创建了数据库,并为其定义了用户名和密码。我正在使用 MysqlConnector。到目前为止,我已经编写了以下代码:

using MySql.Data.MySqlClient;
        MySqlConnection c = new MySqlConnection("SERVER = 64.191.12.54; DATABASE = alyataco_test4application; User ID = xxxxxxxx; PASSWORD = xxxxxxxx");
        c.Open();

但我得到了错误:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.

我也看到了Connect to remote MySQL database with Visual C#,但也没有用

【问题讨论】:

  • 尝试ping服务器或通过查询浏览器连接,检查是否是连接错误
  • 错误是:MySql.Data.MySqlClient.MySqlException:无法连接到任何指定的 MySQL 主机。 ,即:服务器就像找不到

标签: c# mysql database mysql-connector


【解决方案1】:

您的连接字符串似乎错误。试试:

MySqlConnection c = new MySqlConnection("server=64.191.12.54; database=alyataco_test4application; uid=xxxxxxxx; pwd=xxxxxxxx");

有关更多连接字符串示例,请参阅http://www.connectionstrings.com/mysql

【讨论】:

    【解决方案2】:

    您的主机可能不允许远程连接到数据库服务器。简单的判断方法是,如果您将项目部署到服务器并且它可以工作。

    【讨论】:

      【解决方案3】:

      在解决方案资源管理器中右键单击您的项目名称。并选择“添加引用”,然后从可用文件中选择“MySQL.data”并添加它。现在我认为它不会出错。

      【讨论】:

        猜你喜欢
        • 2023-03-10
        • 2019-12-22
        • 2021-10-26
        • 1970-01-01
        • 2018-12-25
        • 2011-06-07
        • 2013-08-02
        相关资源
        最近更新 更多