Reputation: 1804
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.
Upvotes: 1
Views: 8626
Reputation: 28162
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:
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.
Upvotes: 6