简体   繁体   中英

Unable to connect to any of the specified MySQL hosts. 6

I hosted my website on web server. I run my website in visual studio using the server database, it worked fine but when i hosted it on the web server, after one day it started giving me this error. Sometimes some pages works fine and sometimes the same pages gives this error. What would be the problem ? Any solution will be appreciable.

This is the error -

    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

and this is my code -

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();
    }

and my web.config file contains connection string as

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

I am new to this please help me.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM