MySQL查询超时
我正在尝试使用 C# 执行查询。问题是,尽管我修改了超时时间,但它抛出了超时异常。 30 秒后引发异常,这是默认值。
using (MySqlConnection conn = new MySqlConnection(connStr))
{
int x = conn.ConnectionTimeout;
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "SELECT AVG(v.value_min) AS minValue FROM values v";
adpter.SelectCommand = cmd;
adpter.Fill(dados);
conn.Close();
}
正如您所看到的,我正在使用 conn.ConnectionTimeout 来检查超时是否配置正确,是的。至少它显示了我配置的时间量(在本例中为 90)。
那么,我该怎么做呢?如何运行长时间查询?
更新:我发布的查询只是一个示例。
I'm trying to execute a query using C#. The problem is that, despite the fact that I modified the timeout period, it thrown a timeout exception. It is rising the exception after 30 seconds, that is the default value.
using (MySqlConnection conn = new MySqlConnection(connStr))
{
int x = conn.ConnectionTimeout;
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "SELECT AVG(v.value_min) AS minValue FROM values v";
adpter.SelectCommand = cmd;
adpter.Fill(dados);
conn.Close();
}
As you can see, I'm using conn.ConnectionTimeout
to check if the timeout is properly configured and, yes it is. At least it shows the amount of time that I configured (in that case 90).
So, how do I do this? How to run a long time query?
UPDATE: The query that I posted is just an example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
MySqlCommand
上设置CommandTimeout
属性而不是连接应该可以解决问题。Setting the
CommandTimeout
property on yourMySqlCommand
instead of the connection should do the trick.