1

I've a connection string like below

"Server=localhost;Uid=root;Pwd='abcd';Database=testdb;charset=utf8;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?

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

Manu Mohan
  • 1,694
  • 2
  • 20
  • 31

1 Answers1

5

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

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. 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.

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

Bradley Grainger
  • 27,458
  • 4
  • 91
  • 108