2

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?

J4N
  • 19,480
  • 39
  • 187
  • 340
  • Please note that [Entity Framework is not Threadsafe](http://stackoverflow.com/questions/4455634/entity-framework-thead-safety) – Ricardo Souza Nov 21 '12 at 14:09
  • I know, every thread has it's own context(and in additions, it's mostly read operations) – J4N Nov 21 '12 at 14:19

2 Answers2

3

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.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Yes, all threads have several open connections, and since currently the database has to swap some data on the hard disk, some request to the server are becomming really slow(making them having an open pool longer) – J4N Nov 21 '12 at 14:04
  • The problem is mostly that our application has been designed for a very high multi-threading(required by customer) and that our test server hasn't thoses ressources. Anyway, thank you for your help – J4N Nov 21 '12 at 14:18
2

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.

Faaiz Khan
  • 332
  • 1
  • 4