【发布时间】: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 如何配置数据库以使用命名管道没有帮助,请查看如何配置数据库
-
永远不要在这样的公共网站上发布您的连接字符串密码......即使它只是一个测试环境