error in mysql connection “The given key was not present in the dictionary”

不问归期 提交于 2020-01-06 19:53:26

问题


I have problem while connecting to mysql database using "ADO.NET Driver for MySQL (Connector/NET)"

I got this exception The given key was not present in the dictionary.

Edit:

MySqlConnection con = new MySqlConnection("Server=localhost;Database=pgs_db;Uid=root;Pwd=;"); 
MySqlCommand com = new MySqlCommand(); 
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.CommandText = "getStudent";
con.Open();

MySqlDataReader dr =com.ExecuteReader(); 
GridView1.DataSource = dr; 
GridView1.DataBind();
con.Close();

回答1:


Without seeing the code, I am guessing you are trying to access a configuration key that does not exist in your application config file.

Edit: After seeing the code sample, the problem is probably not with connecting to the DB.

I would say that in your GridView, you are binding to a field that is not returned by the DB query.




回答2:


sorry i was using a worng connectionstring

this is a right one :

"server=localhost; user id=user; password=password; database=mydatabase; pooling=false;"

thnx Oded



来源:https://stackoverflow.com/questions/2176329/error-in-mysql-connection-the-given-key-was-not-present-in-the-dictionary

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