executereader永远不会返回

时间:2009-10-02 08:11:05

标签: c# ado.net executereader

我通过devart dotconnect使用mysql。上面的代码是多线程类的一部分。

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();
            }
        }

1 个答案:

答案 0 :(得分:0)

你只是通过博士才能稍后处理它?您还应该阅读读者以获取数据。

while (reader.Read())
    {
        Console.WriteLine(String.Format("{0", reader[0]));
    }