无法连接到任何指定的MySQL主机。 6

时间:2016-09-12 13:06:33

标签: mysql asp.net webserver

我在网络服务器上托管了我的网站。 我使用服务器数据库在visual studio中运行我的网站,它工作正常但是当我在Web服务器上托管它时,一天后它开始给我这个错误。 有时一些页面工作正常,有时相同的页面会出现此错误。 会出现什么问题? 任何解决方案都会很明显。

这是错误 -

    Server Error in '/AttWeb' Application.

Unable to connect to any of the specified MySQL hosts.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

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

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
   MySql.Data.MySqlClient.NativeDriver.Open() +1268
   MySql.Data.MySqlClient.Driver.Open() +22
   MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +218
   MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +287
   MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +93
   MySql.Data.MySqlClient.MySqlPool.GetConnection() +65
   MySql.Data.MySqlClient.MySqlConnection.Open() +543
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2086
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +278
   System.Web.UI.WebControls.ListControl.PerformSelect() +37
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
   System.Web.UI.Control.PreRenderRecursiveInternal() +88
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4775

这是我的代码 -

private MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
    protected void keepData()
    {
        MySqlCommand cmd = new MySqlCommand("select deptName, year from subject where subId = '" + Request.Cookies["subject"].Value + "';", con);
        try
        {
            con.Open();
            MySqlDataReader result = cmd.ExecuteReader();
            if (result.Read())
            {
                Response.Cookies["deptName"].Value = result["deptName"].ToString();
                Response.Cookies["year"].Value = result["year"].ToString();
            }
        }
        catch (MySqlException s) { Label1.Text = "Connection Failed"; }
        catch (Exception ex) { Label1.Text = "Network Error"; }
        con.Close();
    }

和我的web.config文件包含连接字符串

    <connectionStrings>
    <add name="DBCS"
         connectionString="Server=MYSQL5016.SmarterASP.NET;Database=db_a0d03d_demo1;Uid=a0d03d_demo1;Pwd=***"
         providerName="MySql.Data.MySqlClient" />

我是新手,请帮助我。

1 个答案:

答案 0 :(得分:-1)

当您尝试连接到其他非本地数据库时,您需要允许远程请求。