0
votes

I have a connection string in my config files like so

add name="entities" connectionString="Data Source=localhost;user id=username;password=somepassword;persist security info=True;database=dbname" providerName="MySql.Data.MySqlClient"

This works with localhost.

As soon as I change the Data Source to Data Source=123.34.45.56 <-- some remote server

I get MySql.Data.MySqlClient.MySqlException: Table 'mydb.Emails' doesn't exist

If I use connection code in c# it will work against the remote server : Example below

MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new 
MySql.Data.MySqlClient.MySqlConnection();
mySqlConnection.ConnectionString = "Data Source=123.34.45.56;user id=username;password=somepassword;persist security info=True;database=dbname";


string conString = mySqlConnection.ConnectionString;
using (MySqlConnection connection = new MySqlConnection(conString)) {
    connection.Open();

    using (MySqlCommand command = new MySqlCommand(
    "SELECT * FROM emails",
    connection)) {

        using (MySqlDataReader reader = command.ExecuteReader()) {
            while (reader.Read()) {
                for (int i = 0; i < reader.FieldCount; i++) {
                    var tr = reader.GetValue(i);  
                }

            }
        }
    }
} 

How come the connection string in the web.config is throwing this error for every table MySql.Data.MySqlClient.MySqlException: Table 'mydb.Emails'doesn't exist.

The tables are there as the c# connection code can open a connection and query the data just fine.

How do I get the connection string to work?

2
Your connection string that you posted has an extra unescaped " that's ending it early. Was that a copy/paste or is that just an error in your entry? - wentimo
That is just an error in the entry. Sorry about that. - Wes
There's plenty of search results on that error. You're not sharing any details about your server, so we can't know what's wrong. Please read How to Ask, show your research and explain what possible causes you have eliminated. - CodeCaster
@CodeCaster, I disagree with your recommendation that Wes seek existing answers or refactor his question, there is uniqueness in his question as the conn string works with the MySql lib/provider in the C# code but not with Entity Framework, this question is something others can learn from in the future - Brian Ogden
If there is an operating system difference between your local machine and the server, this can change whether items are case sensitive or case insensitive. This could lead to tables not being found, see : dev.mysql.com/doc/refman/5.7/en/… - John Garrard

2 Answers

5
votes

John Garrard was correct. It was a case sensitivity issue with the database located on two different operating systems. I needed to make my entities case sensitive and the switching the connection string will work between the Windows development machine and the Linux production machine. Thanks.

0
votes

I came across this issue when moving from a Windows dev to AWS test system. There is a parameter called "lower_case_table_names" that controls how MySql matches table names which defaults to 0 on linux and 1 in Windows (meaning case sensitive and insensitive):

  • On your AWS Console go to the RDS page.
  • Click on Parameter Groups.
  • Either create your own or click into the default parameter group.
  • Search for the parameter lower_case_table_names.
  • Edit the value and set it to 1
  • Save the parameters and restart the db instance.