MySQL查询超时

发布于 2024-08-21 00:23:50 字数 520 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2024-08-28 00:23:50

MySqlCommand 上设置 CommandTimeout 属性而不是连接应该可以解决问题。

Setting the CommandTimeout property on your MySqlCommand instead of the connection should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文