Connect MySQL Connector NET to connect MySQL using the correct connection string

xiaoxiao2021-03-06  37

When using MyodBC or MySQLDRIVERCS to connect the MySQL database, we only need to enter the database host address, the database name, the database access account, and the access password of the database can be used normally.

But Mysql Connector Net is not the case.

When using "host = localhost; database = test; uid = root; pwd =;" When this string is connected to MySQL, the Chinese characters saved to the database always become similar to the US Word. No solution, suspect is mysql 4.1.x to use the UTF-8 character set to save the data, so change back to MySQL 4.0.22. Try again, the problem is still. It seems that the problem is on the MySQL Connector Net. Open the help of the MySQL Connector Net, turn it to the part of MySQLConnection, and find the answer in a row. The results found that there is a Charset -or Character set parameter in the parameter list. The parameters are described as follows:

Specifies the Character Set That Should Be Used to Encode All Queries Sent To The Server. ResultSets Are Still Returned In The Character Set of the Data Returned.

It turns out that ...

Change the connection string to "Host = localhost; database = test; uid = root; pwd =; charset = GB2312" Try again, OK, this is everything normally!

PS: When using the new version of phpMyAdmin to access mysql 4.1.x, there will be a stuff called the connection character set. At that time, I found that there was no change (because the database, data sheets and fields were all English -_- |||), even if they didn't care. Now think about it, it should be a Dongdong similar to this charset parameter.

转载请注明原文地址:https://www.9cbs.com/read-75730.html

New Post(0)