0

My connection is as follow:

string conString = "server = 10.10.76.150; user id = root1; port 3306; password = root1; charset = utf8";
MySqlConnection conn = new MySqlConnection(conString);
conn.Open();

When I insert some data into table, values are inserted successfully. But when I run Select * query, it gives me exception as "Given key was not present in the dictionary at cmd.ExecuteReader"

string sqlString = "Select * from table1";
MySqlDataCommand cmd = new MySqlCommand(sqlString, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
Ehtesham
  • 3
  • 5
  • Can you share your table definition? – Rohan Rao May 11 '20 at 10:51
  • Table has 3 columns of type int (id, user1, user2) – Ehtesham May 11 '20 at 10:52
  • Aren't you are missing the database name in your connectionstring? It should be of this format: server=10.10.76.150;user id=root1;password=root1;database=dbname;charset=utf8;pooling=false – Rohan Rao May 11 '20 at 11:14
  • But insert query is working fine. – Ehtesham May 11 '20 at 11:15
  • Something is wrong with your connection string. You can visit this link for more information: https://stackoverflow.com/questions/2176329/error-in-mysql-connection-the-given-key-was-not-present-in-the-dictionary – Rohan Rao May 11 '20 at 11:17
  • Could you try to specify columns explicitly in the query: *select id, user1, user2 ...*? – Iliar Turdushev May 11 '20 at 11:28
  • I specified the columns in query, but same result. – Ehtesham May 11 '20 at 11:32
  • I thouhgt that your problem had the same reason as this problem: https://stackoverflow.com/questions/41930040/net-mysql-error-the-given-key-was-not-present-in-the-dictionary. Take a look at this link. May be some of the solutions will help you. – Iliar Turdushev May 11 '20 at 11:49
  • You're likely running into a MySQL Connector/NET bug, either https://bugs.mysql.com/bug.php?id=72737 or https://bugs.mysql.com/bug.php?id=93527. Try switching to https://www.nuget.org/packages/MySqlConnector/ instead. – Bradley Grainger May 11 '20 at 13:33

0 Answers0