We are building an application which makes every week a very large amount of request over the database, concurrently.

We have ~15-20 threads which query the database concurrently.

We are actually encountering a lot of problems:

On the database side(not enough RAM): being resolved.

But on the client too. We have Exception when trying to get a connection or execute commands. Those commande are mades through entity framework.

The application has two part: one website and one console application.

So can anyone tell me how to increase the following values?

  • Connection Timeout
  • Command Timeout
  • Connection pool size

I think that there several things that have to be done on the server side(SQL Server or IIS), but I can't find where?

11/21/2012 1:17:06 PM

Accepted Answer

Command timeout can be set on ObjectContext instance. Connect timeout and connection pool size is configured in connection string but if you have only 15-20 threads your problem will most probably be somewhere else because default connection pool size is 100.

11/21/2012 1:58:18 PM

Popular Answer

Enclose your objectContext in a using block so the context disposes after you have done your work.

you can make a method to pass in thread which uses your entity context to do the work you want and then dispose the connection after the work is finished, you can use the stateinfo object variable to pass in different parameters to use during the life of your method.

void DoContextWork(object stateInfo)

    // wrap your context in a using clause
    using(var objectContext = new YourEntity()
           // Do work here


you can have multiple threads call this method and each time your connection gets called you can do your work on your DB without getting the issues you mentioned above.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow