简体   繁体   English

远程服务器声明表不存在

[英]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" 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一旦我将数据源更改为 Data Source=123.34.45.56 <-- 一些远程服务器

I get MySql.Data.MySqlClient.MySqlException: Table 'mydb.Emails' doesn't exist我得到MySql.Data.MySqlClient.MySqlException: Table 'mydb.Emails'不存在

If I use connection code in c# it will work against the remote server : Example below如果我在 c# 中使用连接代码,它将对远程服务器起作用:下面的示例

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.为什么 web.config 中的连接字符串会为每个表MySql.Data.MySqlClient.MySqlException: Table 'mydb.Emails'抛出此错误MySql.Data.MySqlClient.MySqlException: Table 'mydb.Emails'不存在。

The tables are there as the c# connection code can open a connection and query the data just fine.表在那里,因为 c# 连接代码可以打开连接并查询数据就好了。

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.我需要让我的实体区分大小写,并且连接字符串的切换将在 Windows 开发机器和 Linux 生产机器之间工作。 Thanks.谢谢。

I came across this issue when moving from a Windows dev to AWS test system.从 Windows 开发人员迁移到 AWS 测试系统时,我遇到了这个问题。 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):有一个名为“lower_case_table_names”的参数,用于控制 MySql 如何匹配表名,该表名在 linux 上默认为 0,在 Windows 中默认为 1(意味着区分大小写和不区分大小写):

  • On your AWS Console go to the RDS page.在您的 AWS 控制台上,转到 RDS 页面。
  • Click on Parameter Groups.单击参数组。
  • Either create your own or click into the default parameter group.创建您自己的或单击进入默认参数组。
  • Search for the parameter lower_case_table_names.搜索参数lower_case_table_names。
  • Edit the value and set it to 1编辑值并将其设置为 1
  • Save the parameters and restart the db instance.保存参数并重启数据库实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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