Why it doesn't work when I use MysqlConnection.open()? [closed]

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

  using System;     using System.Collections.Generic;     using System.Linq; using System.Text; using MySql.Data.MySqlClient;   namespace dbTest {     class Program     {         static void Main(string[] args)         {          string sqlStr   = "Database=weather;Server=127.0.0.1;Uid=root;Password=123456;pooling=false;CharSet=UTF8;port=3306";            MySqlConnection mysql = new MySqlConnection(sqlStr);               mysql.Open();               Console.WriteLine("SUCCESS");                mysql.Close();         }     } } 

It will crash when running the sentence "mysql.Open()"

does anybody know why? the error message is: -unhandled exception:System.Collecions.Generic.KeyNotFoundException:the key is not in the dictionary -in System.Collections.Generic.Dictionary'2.get_Item(TKEY KEY) -in Mysql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version,String CHARSETNAME) -in Mysql.Data.MySqlClient.CharSetMap.GetEncoding(DVversion version,String CharSetName) -in Mysql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) -in Mysql.Data.MySqlClient.Mysqlconnection.Open() -in dbTest.Program.Main(String[] args) location:blahblah...

回答1:

You're specifying an invalid character set. Take a look at this reference:

Note! Use lower case value utf8 and not upper case UTF8 as this will fail.

The value is case-sensitive and should be lowercase:

Database=weather;Server=127.0.0.1;Uid=root;Password=123456;pooling=false;CharSet=utf8;port=3306 

Admittedly it's an unhelpful error message, but it is what it is I suppose. (This is why reading a stack trace can often be more helpful than the message itself, since it can provide a basis for researching the answer.)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!