执行读取器永远不会返回
我通过 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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您通过 Dr 只是为了稍后处理它吗?您还应该从阅读器中读取以获取数据。
You are passing Dr only to do dispose it later? You also should read from reader to get data.