What is the correct way to deal with / avoid sql TimeOut error?

0

I was developing an application in which I launch queries automatically, consecutively, always the same.

The problem comes when the DB is slow to respond, in some way, without knowing why, perhaps due to the traffic or the amount of information, the query takes longer than it should, causing the TimeOut Error

The message that comes to me is

  

MySql.Data.MySqlClient.MySqlException:    'Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. '

I keep the queries in a List<String> to not throw them all at once using Union and not overload the DB.

for(int i = 0; i<consultas.Count;i++){
   consulta.CommandText = querys[i];
   dr = consulta.ExecuteReader();
}

Treating the exception does not solve the problem, since data can not be missing .

Is there a way to avoid TimeOut?

    
asked by Aritzbn 12.02.2018 в 10:26
source

1 answer

0

Since I can not speed up the time of the consultations since they are very simple things of

select count(*)
where esto = esto
and esto = esto
group by esto

What I ended up doing is a consulta.CommandTimeout = 900; applied on the MySqlCommand consulta

(I did not know the property of CommandTimeout)

    
answered by 12.02.2018 / 12:24
source