【问题标题】:error in mysql connection "The given key was not present in the dictionary"mysql连接中的错误“字典中不存在给定的键”
【发布时间】:2010-02-01 11:33:36
【问题描述】:

我在使用“ADO.NET Driver for MySQL (Connector/NET)”连接到 mysql 数据库时遇到问题

我收到了这个异常The given key was not present in the dictionary.

编辑:

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();

【问题讨论】:

  • 贴出抛出异常的代码。
  • 发布完整的异常堆栈跟踪也可能会有所帮助。

标签: asp.net mysql connection-string


【解决方案1】:

对不起,我使用了一个破旧的连接字符串

这是正确的:

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

thnx Oded

【讨论】:

  • 现在当我尝试使用连接字符串时,我得到“找不到资源”。我的代码变得更糟了。
【解决方案2】:

如果没有看到代码,我猜您正在尝试访问应用程序配置文件中不存在的配置键。

编辑: 看到代码示例后,问题可能不是连接到数据库。

我想说的是,在您的 GridView 中,您正在绑定到数据库查询未返回的字段。

【讨论】:

  • 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 = 博士; GridView1.DataBind(); con.Close();
  • 我没有使用配置文件,我的连接字符串是上面的纯文本
  • 在评论后更改了答案。 @mahmoud - 发布代码示例时,请将它们添加到问题中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-18
  • 1970-01-01
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
相关资源
最近更新 更多