c# - 连接的主机未能响应,超时已过

标签 c# .net mysql

我在 mysql 中尝试这个查询,它工作正常,但查询花费了 103.5772 秒

SELECT doctor, 
       SUM(medicine) medicine, 
       sum(radiology) radiology, 
       sum(lab) lab, 
       sum(act) act
FROM ( SELECT max(doctor) doctor, 
  sum( if( pm = 'F', cost, 0.00 ) ) medicine,
  sum( if( pm = 'R', cost, 0.00 ) ) radiology,
  sum( if( pm = 'L', cost, 0.00 ) ) lab,
  sum( if( pm = 'P', cost, 0.00 ) ) act
  FROM my_table
  GROUP BY no
  )t
GROUP BY doctor

我的表数据量很大(近200万条数据)

当我在 .net 中尝试时,出现错误

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

我可以增加连接超时吗?

n.b. 我用这个查询来连接数据

conn.ConnectionString = conection.getConnection();
MySqlDataAdapter da = new MySqlDataAdapter(query, conn);
da.Fill(ds);
return ds;

最佳答案

这不是连接超时,而是由于您的数据导致命令超时。如下调整超时;

Command.CommandTimeout = 300;

了解更多信息:SqlCommand.CommandTimeout Property

我还建议您查看索引,看看是否可以优化查询。

关于c# - 连接的主机未能响应,超时已过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13745433/

相关文章:

MySQL - 聚合来自两个表的信息

php - 如何获取公共(public)布局文件的数据并显示在所有 View 上

c# - 使用反射获取方法描述

mysql - VB.NET使定时器作为基于数据库数据表时间的响应时间

c# - Active Directory PrincipalContext.ValidateCredentials 域消歧

c# - 我可以从一个字符串开始并实例化该字符串的对象吗?

.net - 如何将 MoneyBookers 与 ASP.NET 应用程序集成?

c# - 如何在 JSON 中指定子类类型(在 REST Web 服务中)

c# - 来自 .Net 的异步电子邮件

c# - 如何向 Visual Studio C++ ATL 项目创建的 COM .dll 添加新函数