简体   繁体   中英

connected host has failed to respond, timeout expired

I try this query in mysql and it works fine but the Query took 103.5772 sec

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

my table has a large amount of data (nearly 2 million data)

when I try in .net, it has an error

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

can I increase the connection timeout?

nb I used this query to connect data

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

This is not a Connection Timeout, it is timing out on the command due to your data. Adjust the timeout as below;

Command.CommandTimeout = 300;

For more information : SqlCommand.CommandTimeout Property

I would also suggest you look at your indexes to see if you can optimise the query.

您可以使用SqlCommand.CommandTimeout属性:

SqlCommand.CommandTimeout = 300;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM