MySql Connection problem

Discussion in 'Databases' started by GiannosAntoniou, Nov 13, 2011.

  1. I developed a web application which is accessing the MySql Server of Winhost. When I run the web application from my computer (running the web server on my computer) everything is fine. But when I upload the web application on the Winhost, I am getting the following error: "Unable to connect to any of the specified MySQL hosts."

    In the /bin folder, I uploaded the MySql.Data.dll file.

    Should I do changes on the web.config file? Has anyone faced the same problem?

    Thanks
     
    Last edited by a moderator: Oct 14, 2015
  2. Both web servers (the one on my computer and the one on Winhost) are using the same version of MySql Connector .Net; version 6.2.3.0

    The code is the following


    using MySql.Data.MySqlClient;
    using System.Data;

    protected void btnOK_Click(object sender, EventArgs e)
    {
    if (!txtEmail.Text.Contains("@")) return;

    String CS = "server=my02.Winhost.com;database=MyDataBaseName;user=myUserName;port=3306;password=MyPassword;";

    MySqlConnection con = new MySqlConnection(CS);

    MySqlCommand com=new MySqlCommand("insert into advertisementmaidsemail(adv_email, adv_date) values (@anEmail,@aDate)",con);
    com.CommandType = CommandType.Text;
    com.Parameters.AddWithValue("@anEmail",txtEmail.Text);
    com.Parameters.AddWithValue("@aDate", DateTime.Now);
    try
    {
    con.Open();
    com.ExecuteNonQuery();
    txtEmail.Text = "Thank you!";
    }
    catch(Exception ex)
    {
    txtEmail.Text = ex.Message;
    }
    finally
    {
    con.Close();
    }


    }
     
    Last edited by a moderator: Oct 14, 2015
  3. Last edited by a moderator: Oct 14, 2015
  4. wow

    WOW. I found out the problem!
    A lesson to learn: the database name from the connection string is case sensitive when is running on Winhost web server!!!!
    It's the only change that I did, and it works!
     
    Last edited by a moderator: Oct 14, 2015
  5. I have the same problem again....so, i guess, the case sensitivity is not the actual problem (or even, not a problem at all).

    Any suggestion? I want to remind you that the web application can access the mysql server of Winhost, when it is running on other machines ( I tried it on 4 web servers). But, when I upload the web application on the Winhost web server, it cannot access the MySql Server!!! :confused:

    Thanks
     
    Last edited by a moderator: Oct 14, 2015
  6. Below is the code.

    String CS = "server=my02.Winhost.com;database=mysqlDB;user=MyLogin;port=3306;password=MyPassword;";
    MySqlConnection con = new MySqlConnection(CS);

    MySqlCommand com=new MySqlCommand("insert into advertisementmaidsemail(adv_email, adv_date) values (@anEmail,@aDate)",con);
    com.CommandType = CommandType.Text;
    com.Parameters.AddWithValue("@anEmail",txtEmail.Text);
    com.Parameters.AddWithValue("@aDate", DateTime.Now);
    try
    {
    con.Open();
    com.ExecuteNonQuery();

    }
    catch(Exception ex)
    {
    txtEmail.Text = ex.Message;
    }
    finally
    {
    con.Close();
    }
     
    Last edited by a moderator: Oct 14, 2015
  7. Elshadriel

    Elshadriel Winhost Staff

    Are you receiving a new error? Also, try placing at @ symbol before the first quotation mark to denote that everything between the quotes is the string literal.
     
  8. Problem with assembly

    Guys if anyone can help me out with this.

    I have:
    using MySql.Data.MySqlClient;
    using System.Data;

    MySqlConnection conn = new MySqlConnection("LocalMySqlServer");
    MySqlCommand cmd = new MySqlCommand("CREATE TABLE test (id INT AUTO_INCREMENT, test VARCHAR)", conn);
    try {
    conn.Open();
    MySqlDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
    Response.Write(dr[0]);
    }
    }
    catch (Exception ex) {
    Response.Write(ex.Message.ToString());
    }


    In web.config i have:


    <connectionStrings>
    <remove name="LocalMySqlServer"/>
    <add name="LocalMySqlServer" connectionString="Server=localhost; Database=mysql_34514_this; uid=***; pwd=****;" providerName="MySql.Data.SqlClient"/>
    </connectionStrings>

    and

    <system.web>
    <compilation targetFramework="4.0">
    <assemblies>
    <add assembly="MySql.Data.SqlClient, Version=6.2.3.0, Culture=Neutral, PublicKeyToken=c5687fc88969c44d"/>
    </assemblies>
    </compilation>
    </system.web>

    And after all this i'm getting this error:

    Could not load file or assembly 'MySql.Data.SqlClient, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
     
  9. fast

    I know there are a lot of errors in the code but the page wont load cuz of web.config. Help me fix this one and i will fix all those others myself.
     
  10. Elshadriel

    Elshadriel Winhost Staff

    The connection string is incorrect. The server is not 'localhost' You can find the server name in the Winhost Control Panel when you click on Manage. The error message also indicates it cannot find the correct version of the .dll file. Make sure you've uploaded the correct version to the /bin folder. If this is a web application in a subdirectory, make sure you also mark the sub-directory as such using the Application Starting Point button.
     
  11. Version

    Thanks for that but how to get version and token number of the library i m downloading?
     
  12. Hello! The problem is not totally same but, it matches much as I have with my database connection. Someone suggest me to opt for dbconnection string tutorial which is really brilliant. It gives me the perfect concept.
    http://www.dbconnectionstrings.org
     
    Last edited by a moderator: Oct 14, 2015
  13. btw

    Ok, lets put it that way.
    1) I have my config file in which i have connection string. There is nothin more there.
    2) To connect to MySql database i need a few objects (like MySqlConnection and others).
    3) They are stored in dll files (like MySql.Data.SqlClient.dll and others).
    4) To help my project find them i am supposed to upload it to the \bin folder.
    5) Then i need to reference it in my web.config? My references look like:
    <system.web>
    <compilation debug="false" targetFramework="4.0">
    <assemblies>
    <add assembly="MySql.Data, Version=6.3.5.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
    </assemblies>
    </compilation>
    </system.web>
    Correct me please if I am wrong in any of these steps. But it gives me the error i already mentioned above. Thanks in advance!
     

Share This Page