【问题标题】:ASP.NET MySQL ConnectionString error "Unable to connect to any of the specified MySQL hosts"ASP.NET MySQL ConnectionString 错误“无法连接到任何指定的 MySQL 主机”
【发布时间】:2015-05-01 18:50:53
【问题描述】:
Source Error (Line 26): 


Line 24: 
Line 25:             conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
**Line 26:             conn.Open();**
Line 27:             queryStr = "";
Line 28: 

我的连接字符串是:

   <connectionStrings>
        <add name="webAppConnString"
        connectionString="Server=mysql6.000webhost.com; Uid=a2867246_root; Pwd=******; Database=a2867246_canvas;"
        providerName="MySql.Data.MySqlClient"/>
    </connectionStrings>

它在 localhost(127.0.0.1) 上运行良好,但是当我尝试使用远程 MySQL 服务器时,它无法连接。错误日志:

[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
   MySql.Data.MySqlClient.NativeDriver.Open() +413
   MySql.Data.MySqlClient.Driver.Open() +75
   MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +268
   MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() +44
   MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +368
   MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +199
   MySql.Data.MySqlClient.MySqlPool.GetConnection() +125
   MySql.Data.MySqlClient.MySqlConnection.Open() +1105
   WebApplication5.Default.submitEventMethod(Object sender, EventArgs e) in c:\Users\****\WebApplication5\Default.aspx.cs:26
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633690
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

【问题讨论】:

  • 检查服务器防火墙和a2867246_root权限,是@还是%。最简单的方法是使用 MySQL 客户端使用用户名和密码从您的 PC 连接到服务器。从消息来看,它看起来更像是防火墙。
  • C# Connection Strings 如果这对 google 如何配置数据库以使用命名管道没有帮助,请查看如何配置数据库
  • 永远不要在这样的公共网站上发布您的连接字符串密码......即使它只是一个测试环境

标签: c# mysql asp.net


【解决方案1】:

我自己以及我认识的其他开发人员都经历过。

其中一个简单的修复方法(开始时执行的标准程序)是将所有参数按正确的顺序,如下所示:

Server=TheServerAddress; Port=YourPortNumber; Database=YourDatabase; Uid=YourUsername; Pwd=YourPassword;

在您的特定情况下,它应该如下所示:

Server=mysql6.000webhost.com; Database=a2867246_canvas; Uid=a2867246_root; Pwd=1234pass1234;

【讨论】:

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