tags:

views:

448

answers:

2

I have some code written that is attempting to connect to a mysql db. I have installed this. I have added a reference which is MySql.Data.CF.dll in the project. The project compiles with no complaints.

When I execute this...

string conn_str = ConfigurationManager.ConnectionStrings["MySQLServer"].ConnectionString;
DataSet m_Dst = new DataSet();
DataTable All_Table = new DataTable();
try
{
    MySqlCommand cmd = new MySqlCommand(m_SQL, new MySqlConnection(conn_str));
    cmd.CommandType = CommandType.Text;
    cmd.Connection.Open();
    MySqlDataAdapter MyDa = new MySqlDataAdapter(cmd);
    MyDa.Fill(m_Dst);
    if (m_Dst.Tables.Count > 0)
        All_Table = m_Dst.Tables[0];
}
catch (Exception ex)
{
    string s = ex.Message;
}

I get an exception as follows:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MySql.Data.MySqlClient.Properties.Resources.resources" was correctly embedded or linked into assembly "MySql.Data.CF" at compile time, or that all the satellite assemblies required are loadable and fully signed."

Does anyone know what I am missing or have done wrong to prevent this connection?

+4  A: 

I would try re-installing the MySql Connector.

Then I would re-write that code like this:

string conn_str = ConfigurationManager.ConnectionStrings["MySQLServer"].ConnectionString;

DataTable All_Table = new DataTable();
using (MySqlConnection cn = new MySqlconnection(conn_str))
using (MySqlCommand cmd = new MySqlCommand(m_SQL, cn))
{
    try
    {
        cn.Open();
        using (MySqlDataReader rdr = cmd.ExecuteReader())
        {
            All_Table.Load(rdr);
            rdr.Close();
        }
     }
     catch (Exception ex)
    {
        string s = ex.Message;
    }
}

You need to be sure you dispose your connection, and the using blocks will do that.

Joel Coehoorn
Yea i plan on disposing it but i was just testing this. And I get this error. I already tried reinstalling so that isnt the solution either. Other ideas ?
gmcalab
I'd take the error message at face value. It's complaining about culture/satellite assemblies, and so I'd make sure the localized version of connector matches your system, or that you've included any needed localization assemblies with the deployment.
Joel Coehoorn
btw, you can use `cn.CreateCommand()` instead `new MySqlCommand(,)`
abatishchev
+1  A: 

I had the same problem. My problem was that I wasn't adding the refference from the .NET panel but from the Browse panel.
After I Installed verion 6.2.3.0 I added the refference from the .NET panel.
It worked like a charm.

Meltdown