1

Possible Duplicate:
MultiThreading error: There is already an open DataReader associated with this Connection which must be closed first

I'm not sure why I'm still having the issue, here is my below code, any help is appreciated.

public static DataTable DTTable(string mysqlQuery, string queryName)
        {
            lock (_object)
            {
                DataTable DTTableTable = new DataTable();
                try
                {
                    using (MySqlDataAdapter DataDTTables = new MySqlDataAdapter(mysqlQuery, MySQLProcessing.MySQLStatic.Connection))
                    {
                        using (DataTable DataDTTablesDT = new DataTable())
                        {
                            DataDTTables.SelectCommand.CommandTimeout = 240000;
                            DataDTTables.Fill(DataDTTablesDT);
                            DTTableTable = DataDTTablesDT;
                            DataDTTables.Dispose();
                        }
                    }

                }
                catch (Exception ex)
                {

                    GenericLogging("Failed MySQLquery: " + ex.Message.ToString(), "MySQLProcessor", "DTTable", "", "MysqlError", "", queryName, mysqlQuery);

                }
                return DTTableTable;
            }
        }
Community
  • 1
  • 1
  • 1
    You're using a static connection. Might it also have another open reader? Create a new connection and try it instead. – Chris Farmer Apr 10 '12 at 00:23
  • @ChrisFarmer There is no other open reader, this is the only code that calls it –  Apr 10 '12 at 00:25
  • It doesn't have to be *this* reader. – Chris Farmer Apr 10 '12 at 00:26
  • 1
    Where is `_object` defined and assigned? – phoog Apr 10 '12 at 00:29
  • @phoog static readonly object _object = new object(); at the begining of the class –  Apr 10 '12 at 00:35
  • as stated above, this post is clearly a duplicate – Fabske Apr 10 '12 at 00:37
  • 1
    In your previous question which seems to be 99% identical to this, someone suggested creating another connection and using that. Why did you choose to ignore that? – Chris Farmer Apr 10 '12 at 00:37
  • @Mike: Having more than one question about the **exact** same topic is going to get confusing really fast. I would abandon this question entirely and focusing all activity on your [previously posted question](http://stackoverflow.com/q/10081042/158779). – Brian Gideon Apr 10 '12 at 00:38
  • @ChrisFarmer Because i put a lock in that code that is not on that question and actually voted to close it –  Apr 10 '12 at 00:38
  • 1
    But judging from the title, both your questions are about the datareader and not about the lock. – Chris Farmer Apr 10 '12 at 00:40
  • @ChrisFarmer it's more about the issue, i don't understand how this section of code can be called twice while there is a lock, how can there be an open reader if it's locked –  Apr 10 '12 at 00:40
  • It doesn't have to be THIS block of code that's using your static connection when you get this error. Are you certain that it's THIS code? – Chris Farmer Apr 10 '12 at 00:41
  • @Mike: Update your [previous question](http://stackoverflow.com/q/10081042/158779) with new or different information. This is the one that is going to get closed since it got posted later. – Brian Gideon Apr 10 '12 at 00:41

0 Answers0