简体   繁体   中英

Remote server claims table doesn't exist

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM