Question Query inside a loop return Time Out

eljallouly

New member
Joined
Jan 5, 2021
Messages
1
Programming Experience
1-3
Hello,

I execute a query inside a loop foreach :

C#:
foreach(var row in List)
{
   .....
   Var result = dbContext.Customers.ToArray();
   .....
}

The table Customer has 280 rows, the Sql query works a great.

In the first loop the query works, but in the second loop a query return a time out.

I don't understand what's a problem.

Thank you.
 
Last edited by a moderator:
Is the code Async?
How many times can your database user open a connection?
Does the code execute while previous request is in transmission of a response?
Can you post the exact response you are getting from the request?

  • Try increasing the size of the connection pool.
  • Consider adding error logging to your application, specifically where this block of code is running.
  • Increasing the connection timeout would also help in cases where your data is still transitioning through the transit tunnels such as VPN, or general connectivity of your network.
  • You should setup appropriate connection exception handlers for when those types of errors occur, and handle them appropriately.
This error can be caused by so many factors. But pay attention to the state of your connection when debugging. You can find a debugging tutorial in my signature. You will also need someone else to assist you after this post, as I will be offline for a while.
 
Back
Top Bottom