I only use DataReaders two times within my application both times it looks like this
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
//Code
}
reader.Close();
Can anyone give me some pointers on how to solve this error? Or where to look? Sorry if it’s too vague but that’s what the error is telling me. It points to this point:
MySqlCommand cmdDel = new MySqlCommand("UPDATE " + _Database + " SET balance=" + balance + ", bitaddress=" + myads + ", lostbalance=" + lostbalance + " WHERE username = '" + username + "'", connection);
cmdDel.ExecuteNonQuery();
cmdDel.Dispose();
My guess is that executing query commands could be not allowed inside of a while(reader.Read()) can anyone confirm on this?
This almost certainly implies that you’re sharing a connection object between multiple command objects. You should avoid doing this (unless they’re all involved in a single database transaction).
The model you should follow generally is:
Unless you have specific needs which prevent it, you should prefer to wrap disposables in
usingstatements, rather than manually callingDispose().