本文介绍了MySQL charset = UTF-8和ConnectionReset = True不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个如下所示的连接字符串

I've a connection string like below

任何插入到带有unicode字符的数据库表列的操作都会插入为特殊字符.如果我删除"ConnectionReset = True;",一切正常.从我的连接字符串.你知道这是怎么回事吗?

Any insertion to a database table column with unicode character is inserted as special characters. Everything works fine if i remove "ConnectionReset=True;" from my connection string.Any idea whats going on here?

注意:,我相信我的代码很好,因为当我从连接字符串中删除ConnectionReset=True;部分时,插入unicode很好.

Note: I believe my code is fine because insertion of unicode is fine when I remove ConnectionReset=True; part from the connection string.

推荐答案

您遇到的是 MySQL错误#85185 :"ConnectionReset池选项不保留CharSet选项值".

You are encountering MySQL Bug #85185: "ConnectionReset pooling option does not preserve CharSet option value".

使用ConnectionReset=true是个好主意;但是,这样做的副作用是将连接字符集重置为服务器默认值,这不是您想要的.我可以想到两种解决方法:

It's a good idea to use ConnectionReset=true; however, this has the side-effect of resetting the connection character set to the server default, which isn't what you want. I can think of two workarounds:

  1. 使用 MySqlConnector (可解决此问题的替代ADO.NET MySQL连接器库)其他)连接器/NET错误
  2. 在每次调用connection.Open()之后执行connection.ExecuteNonQuery("SET NAMES utf8mb4");.从池返回连接后,这将修复连接字符集后的连接字符集.
  1. Use MySqlConnector, a replacement ADO.NET MySQL connector library that fixes this (and many other) Connector/NET bugs
  2. Execute connection.ExecuteNonQuery("SET NAMES utf8mb4"); after each call to connection.Open(). This will fix the connection character set after a connection is reset when it's returned from the pool.

最后,MySQL utf8字符集实际上不是 UTF-8,因此改用utf8mb4 .

Finally, the MySQL utf8 character set is not actually UTF-8, so use utf8mb4 instead.

这篇关于MySQL charset = UTF-8和ConnectionReset = True不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:56