views:

122

answers:

1

i am using mysql via devart dotconnect. above code is part of the multithreaded class.

public  void DoQuery(ref Devart.Data.MySql.MySqlDataReader Dr, string QryStr)
        {
            lock (locker)
            {
               //Program.MyMutex.WaitOne();
                Devart.Data.MySql.MySqlCommand Command = new Devart.Data.MySql.MySqlCommand();
                int ThreadID = Convert.ToInt32(Thread.CurrentThread.Name);
                MySqlConnection FCon = Program.Con[ThreadID];
                if (FCon.State != System.Data.ConnectionState.Open) Program.Con[ThreadID] = Program.BuildDbConnection();
                Command.Connection = FCon;
                Command.CommandTimeout = 0;
                Command.FetchAll = true;
                Command.CommandText = QryStr;
                if (Dr != null) Dr.Dispose();
                if (QryStr.Substring(0, 6).Equals("select", StringComparison.CurrentCultureIgnoreCase) != true) Command.ExecuteNonQuery(); else Dr = Command.ExecuteReader(); this line randomly stuck on ExecuteReader.
                Command.Dispose();
            }
        }
A: 

You are passing Dr only to do dispose it later? You also should read from reader to get data.

while (reader.Read())
    {
        Console.WriteLine(String.Format("{0", reader[0]));
    }
this method returns dr to caller method so i can use it there.
Aeon