Non-ASCII Connection String Issues
Posted by: Elliott Hamai
Date: August 13, 2013 09:48AM

Hi there,

I apologize if this is a stupid question but I couldn't seem to find an answer for this. I'm trying to use MySql Connector to connect to a database that has Chinese characters in it but it doesn't appear to work due to decoding issues. Here's the code I'm using:

MySqlConnection conn = new MySqlConnection(@"server=localhost;database=数据库;uid=root;pwd=password;"); // Also tried adding "charset=utf8;" to connection string without success
conn.Open();

And I get this error:

MySqlException: Unknown database '???'
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()\r\n
at MySql.Data.MySqlClient.NativeDriver.AuthenticateNew(Boolean reset)\r\n
at MySql.Data.MySqlClient.NativeDriver.Authenticate(Boolean reset)\r\n
at MySql.Data.MySqlClient.NativeDriver.Open()\r\n
at MySql.Data.MySqlClient.Driver.Open()\r\n
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)\r\n
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()\r\n
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()\r\n
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()\r\n
at MySql.Data.MySqlClient.MySqlPool.GetConnection()\r\n
at MySql.Data.MySqlClient.MySqlConnection.Open()\r\n
at APITest01.Program.Main(String[] args)

It appears to me as if the server is decoding the string incorrectly because the error message returned changes the database name to '???' instead of '数据库'.

We can work around this issue by connecting at the server level (without specifying database name) and then issue a "USE 数据库;" command which works. This implies to me that the initial connection itself needs to be in ASCII, but the session thereafter can be Unicode. Unfortunately this does not help if the username or password is using Chinese characters as well since we need to include that in the connection string.

Does anyone know if I am missing something simple here or if this is a real bug with MySQL Connector. Any help is appreciated. Thanks!

P.S. I chose some random Chinese characters to test with so if they mean something bad, I apologize. :P

Options: ReplyQuote


Subject
Written By
Posted
Non-ASCII Connection String Issues
August 13, 2013 09:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.