【问题标题】:Special characters replaced with question marks in MySql response from .net using MySqlConnection使用 MySqlConnection 在来自 .net 的 MySql 响应中用问号替换特殊字符
【发布时间】:2019-09-25 17:05:26
【问题描述】:

我在我的 .net 应用程序中使用 MySqlConnection 从 .net 应用程序查询 MySql 数据库,但我的结果集中的特殊字符(它是丹麦语)显示为问号。我试过在我的连接字符串中包含“charset”(charset=utf8),但没有任何运气。

【问题讨论】:

  • 首先检查您的表格使用的是哪个 character4set 和排序规则,可能不是 utf8
  • 非常感谢您的回复!该表设置为 latin1_danish_ci

标签: c# mysql .net ado.net


【解决方案1】:

尝试连接

Server=localhost;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;CHARSET=latin1;

然后

partial void OnContextCreated()
{
    System.Data.Common.DbCommand command = this.Connection.CreateCommand();
    command.CommandText = "set collation_connection = utf8_slovenian_ci;";
    command.CommandType = System.Data.CommandType.Text;
    this.Connection.Open();
    command.ExecuteNonQuery();
}

就像这里描述的Database connection string and collation

【讨论】:

    猜你喜欢
    • 2019-07-22
    • 1970-01-01
    • 2021-08-02
    • 2018-08-23
    • 1970-01-01
    • 2014-11-03
    • 2012-04-27
    • 2016-06-13
    • 2019-09-23
    相关资源
    最近更新 更多