Sql datareader already associated high frequency polling

I've a block of code that gets executed every ~ 0.25 seconds. It works fine for around the first ten iterations until it crashes with an "Datareader already associated with this connection" error, despite the fact that I am closing the data reader being used every time. Could the speed of the requests be causing this? I slowed it down to executing every 1.5 seconds and it still happened. This connection is used nowhere else bar this block so I'm not sure why its happening. I'm using MySQL so I cannot turn on multible active sets.

 MySqlCommand cmd = new MySqlCommand(QueryString, connection); var dataReader = cmd.ExecuteReader(); var dt = new DataTable(); dt.Load(dataReader); dataReader.Close(); dataReader.Dispose(); cmd.Dispose(); 

by Borderboy-_- via /r/csharp

Leave a Reply