none
mysql connection string RRS feed

  • Question

  •  

    i'm trying to connect to mysql database hosted by a web hoster but can't please help.

     

    here is my connection string.

     

    Driver={MySQL ODBC 3.51 Driver};Server=htt://www.maphim.com;Port=3306;Option=131072;Stmt=; Uid=maphimco;Pwd=******; Option=3;

    got it from connectionstring.com

     

    when i compile, it say it does not recognize "Driver, option, and stmt" do you know why?

    Sunday, April 6, 2008 12:43 AM

Answers

  • First, i think the latest MySqlClient is 5.0.8.1

     

    Second, please try checking if the token in your app config is correct. it should look like below.

    <system.data>
      <DbProviderFactories>
       <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient1" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.0.8.1, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
      </DbProviderFactories>
     </system.data>

    Sunday, April 6, 2008 3:36 AM

All replies

  • I use in this way:

    string connStr = String.Format("server={0}; user={1}; password={2}; database={3};",
                        local, user, pass, base);

    Mello.
    Sunday, April 6, 2008 1:04 AM
  • Hi,

     

    Just a piece of help. There is a MySql client for .net that you can use. It is called MySql.Data.dll, you can download it from the mysql website and reference it to your data layer. it works very similar to SqlClien. Below is the code where i use MySql Client.

     

    At config file int he connection string element you can add this code.

    <add name="MYSQLCONN" connectionString="server=servername; userid=user;password=password;pooling=yes;Database=DBName" providerName="MySql.Data.MySqlClient"/>

     

    or you can have it in your C# code embeded to what you usually do with normal SQL connection.

     

    Sunday, April 6, 2008 1:35 AM
  • i found the mysql connector but it say it only support .net 1.0 do you know where i can download one that support .net 3.5?

    Sunday, April 6, 2008 2:45 AM
  • i found 1 that works but got another problem.

    here is my code

     

     

    private void DDListDatabase_Click(object sender, EventArgs e)

    {

    //<add name="MYSQLCONN" connectionString="server=servername; userid=user;password=password;pooling=yes;Database=DBName" providerName="MySql.Data.MySqlClient"/>

    string connStr = "server=http://www.maphim.com; userid=maphimco;password=******;pooling=yes;";

    //"Server=htt://www.maphim.com;Uid=maphimco;Pwd=tethiendaithanh;"

    DDListDatabase.Items.Add("test13");

    try

    {

    using (MySql.Data.MySqlClient.MySqlConnection sqlConx = new MySql.Data.MySqlClient.MySqlConnection(connStr))

    {

    sqlConx.Open();

    System.Data.DataTable tblDatabases = sqlConx.GetSchema("Databases");

    sqlConx.Close();

    foreach (System.Data.DataRow row in tblDatabases.Rows)

    {

    // DDListDatabase.Items.Add(row["database_name"]);

    DDListDatabase.Items.Add("test1");

    }

    }

    }

    catch (System.Data.SqlClient.SqlException ae)

    {

    TboxError.Text = ae.ToString();

    //MessageProgress.Text = "We are unable to connect to the database\n" + MessageBox.Show(ae.Message.ToString());

    }

     

     

    got an error

    "System.Net.Sockets.SocketException: No such host is known"

     

    do you know what this mean and how to fix this?

    Sunday, April 6, 2008 2:57 AM
  • First, i think the latest MySqlClient is 5.0.8.1

     

    Second, please try checking if the token in your app config is correct. it should look like below.

    <system.data>
      <DbProviderFactories>
       <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient1" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.0.8.1, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
      </DbProviderFactories>
     </system.data>

    Sunday, April 6, 2008 3:36 AM
  •  Romeomussluv wrote:

     

    string connStr = "server=ServerIP here; userid=maphimco;password=******;pooling=yes;";

     

     

    Above is not correct it should be Server IP that you should include. Try again.

    Sunday, April 6, 2008 3:39 AM
  • Thank you very much all especially Bermil.  i got it to work.  it turns out, i need the IP address, i put in my host name Smile...

     

    one quick question though,  how do i get my connection string at my webconfig,

     

     

    here is a sample,

     

    private void DDListDatabase_Click(object sender, EventArgs e)

    {

    //<add name="MYSQLCONN" connectionString="server=servername; userid=user;password=password;pooling=yes;Database=DBName" providerName="MySql.Data.MySqlClient"/>

    string connStr = "server=74.220.207.80; userid=maphimco;password=****;pooling=yes;";

    //"Server=htt://www.maphim.com;Uid=maphimco;Pwd=tethiendaithanh;"

    DDListDatabase.Items.Add("test13");

    try

    {

    using (MySql.Data.MySqlClient.MySqlConnection sqlConx = new MySql.Data.MySqlClient.MySqlConnection(connStr))

    {

    }

     

    i use this but i need to know how to use the connection string at the web config file Smile..

    Sunday, April 6, 2008 3:40 AM
  • To get the connection string from the config file you need to do like this

     

    DbProviderFactory _factory = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings["The Name of the Connection string from config file"].ProviderName);

     

    OR

     

    string _connectionString = ConfigurationManager.ConnectionStrings["The Name of the Connection string from config file"].ConnectionString;

     

    But you need to reference System.Configuration to your project.

     

    Sunday, April 6, 2008 3:48 AM
  • man is there anything you dont know ? Smile  thanks a bunch. 

     

    Sunday, April 6, 2008 4:01 AM