不知道为什么每次尝试连接时都会收到错误。我尝试了很多东西。当我手动连接时输入错误的密码时,它表示访问未授予或任何我知道它连接,但当它连接时,我得到这个奇怪的错误。由于KeyNotFoundException而无法连接到MySQL数据库
类型 “System.Collections.Generic.KeyNotFoundException”的未处理的异常发生在 mscorlib.dll中其他信息:在 词典中的给定的键不存在。
对于本地主机它有效当我有这个连接字符串。
server=localhost; port=3306; USER ID=root; password=***; database=database;
但是,当我更改服务器用户ID和密码它决定不工作。
例外情况引发cn.Open()
;
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection cn = new MySqlConnection();
cn.ConnectionString = "server=db4free.net ;port=3306;
user=goof; password=pwd; database=s;";
cn.Open();
MySqlCommand cmd = new MySqlCommand("select * from users where
username = '"
+ textBox1.Text + "',
and password = '"
+ textBox2.Text + "'", cn);
MySqlDataReader dr;
dr = cmd.ExecuteReader();
int count = 0;
while(dr.Read())
{
count += 1;
}
if(count == 1)
{
MessageBox.Show("success");
}
else
{
MessageBox.Show("error");
}
}
只要我知道,MySQL使用“Uid and Pwd”作为用户名和密码,而不是连接字符串中的“user和password”。 –
亚我已经尝试过,所以现在失去了: –
试试这个> http://stackoverflow.com/questions/2176329/error-in-mysql-connection-the-given-key-was-not-present-in-the-dictionary错误的连接字符串“pooling = false” –