asp.net连接mysql字符校对不匹配

今天升级了一个原来由Visual Studio 2002开发的一个asp.net+mysql项目,升级到.net framework 2.0后,编译没有任何错误,但居然不能运行了,提示信息如下:

Illegal mix of collations (latin1_swedish_ci,IMPLICIT), (gb2312_chinese_ci,COERCIBLE), (gb2312_chinese_ci,COERCIBLE)

解决办法如下:
1,修改数据库/表/字段的编码.
2,执行之前加上set names latin1;
3,更改my.ini的init-connect=” latin1″(没有则加上).
4,查询时加上强制字符编码转换
   select * from table where name = ‘xxx’ COLLATE latin1_swedish_ci

This entry was posted in ASP.NET, DataBase. Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word