Unable to connect to any of the specified MySQL hosts

Last post 03-05-2009 3:54 AM by mona.said. 4 replies.

Sort Posts:

  • Unable to connect to any of the specified MySQL hosts

    05-15-2008, 7:43 AM
    • Member
      4 point Member
    • Sirsiljas
    • Member since 08-21-2007, 6:25 PM
    • Posts 17

    Hello friends

    I am trying to connect to my MySql database on a dedicated server (from my home computer), but i keep running into different kind of errors. I keep debugging and try to solve the problems, but the last error is kinda driving me crazy, so I hope you can help me with my problem.

    1. I have installed MySQL Connector .Net 5.2.1
    2. I have installed MySQL Connector ODBC
    3. I have created a new Project in VWD 2008 Express and included the MySql.Data.dll into my Bin folder
    4. And I use the following code to connect to my MySql database:

    Web.config:

       <connectionStrings>
        <add name="myConStr" connectionString="server=serverIP; database=dbName; user id=uName; password=pName;"/>
      </connectionStrings>

    MasterPage.master.cs

    using MySql.Data.MySqlClient;

    ....

    try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString.ToString()))
                {
                    con.Open();
                    using(MySqlCommand cmd = new MySqlCommand("SELECT [field1] FROM [table] WHERE [field2] <= 10", con))
                    using(MySqlDataReader dr = cmd.ExecuteReader())
                    {
                        ddlUsers.DataSource = dr;
                        ddlUsers.DataBind();
                        dr.Close();
                    }
                    con.Close();
                }

            }
            catch(Exception ex)
            {
                errorMsgTop.Text = ex.Message.ToString();
               
            }

    dllUsers is an <asp:DropDownList>.

    But I keep getting this error:

    error msg: Unable to connect to any of the specified MySQL hosts.
    error source: MySql.Data

    It's complaining about con.open(). I've tryed to connect with these database login values with my other (classic ASP) projekt and it works fine, but I can't make it work with ASP.NET. Can you please help me with this problem?

    http://www.aspKoll.se - Swedish ASP, ASP.NET, AJAX community
  • Re: Unable to connect to any of the specified MySQL hosts

    05-16-2008, 12:35 PM
    • Member
      70 point Member
    • Webmonkeymon
    • Member since 03-14-2007, 8:37 PM
    • Posts 51

    i have the same error.

     However I am not using the .net connector

    i tried odbc and switched all the code to use the MySqlConnection but still same d@#$ thing.

    I can connect fine through visual studio, through MySql Administrator and MySqlQuery browser.

    For now I am connecting to another machine on my home network, but tried to two other remote mysql databases first.

    I have tried endless combinations of connection strings!   Almost all of them work using visual studio or query browser.

    This is very important to me.  thanks 

     

    hittem in the head ed.
  • Re: Unable to connect to any of the specified MySQL hosts

    05-18-2008, 4:18 AM
    Answer
    • Member
      65 point Member
    • daxmax
    • Member since 04-16-2008, 9:42 PM
    • Posts 29

    Here is my suggestion. Set up the server you want to work with on the Data Connections tab of  Visual Studio. With the 5.2.1  install of the .NET MySQL connector, it also installs some nifty features into VS like being able to view\edit\query,etc. to the Mysql database  from the Data connections window.   My point here is to check to see if the data connection, which is the formal way that mySQL developers suggest you create a tie in to your database, works.  You could have a firewall, norton,  etc. issue or it could be specific to Visual studio. Are you able to connect via MySQL Query browser?   Check the permissions and if push comes to shove, load up a  http sniffer to see if the requested connection is actually going to the remote server and coming back with a response.

    "the veil has been lifted."
  • MySql.Data.MySqlClient does not contain any public member

    06-19-2008, 8:17 AM
    • Member
      70 point Member
    • Webmonkeymon
    • Member since 03-14-2007, 8:37 PM
    • Posts 51

     

    daxmax:
    Data Connections tab

    That post was helpful and I did connect. 

    Now I am back at this again but this time I cannot get the mysql.web.dll to register. 

    MySql.Data.MySqlClient does not contain any public member

    the mysql.web.dll will not register.   The mysql.data.client cannot find theNamespace.

    i have added them to the projects, put the dll in the web bin folder, built the solutions and the built the website. 

    I also have another project open and working with a registered mysql. 

    I do not have it in the full project source code.  The full project shows me dependancies but will not let me add one.  

    I should have documented this better the first time. Smile

    -- i will this time.

    thanks

     

    hittem in the head ed.
  • Re: Unable to connect to any of the specified MySQL hosts

    03-05-2009, 3:54 AM
    • Member
      2 point Member
    • mona.said
    • Member since 03-05-2009, 3:50 AM
    • Posts 1
    hi all i had the same problem and i fixed it be reconfigure the MYSQL itself as it by default not allow to connect other machine to it. so check that is use as Server not developer, i hope it fix the problem cheers :), Mona said
Page 1 of 1 (5 items)