【发布时间】:2014-09-19 12:04:20
【问题描述】:
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();
}
}
}
运行语句“mysql.Open()”会崩溃
有人知道为什么吗? 错误信息是: -未处理的异常:System.Collecions.Generic.KeyNotFoundException:密钥不在字典中 -在 System.Collections.Generic.Dictionary'2.get_Item(TKEY KEY) -在 Mysql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion 版本,字符串 CHARSETNAME) -在 Mysql.Data.MySqlClient.CharSetMap.GetEncoding(DVversion 版本,字符串 CharSetName) - 在 Mysql.Data.MySqlClient.Driver.Configure(MySqlConnection 连接) -在 Mysql.Data.MySqlClient.Mysqlconnection.Open() -in dbTest.Program.Main(String[] args) location:blahblah...
【问题讨论】:
-
KeyNotFoundException?您确定此异常来自其他地方吗? -
我不知道为什么会这样。
-
大概是因为某个键不在字典中。也许您可以分享整个错误(包括堆栈跟踪),或者我们应该只是猜测?
-
"unhandled exception:System.Collecions.Generic.KeyNotFoundException:key is not in the dictionary"将显示在控制台窗口中..
-
阅读@David 的全部评论。更新您的问题以显示该异常的完整堆栈跟踪。