LINQ - Connection Pooling with Entity Framework

Asked By Swapnil Salunke on 08-Dec-08 07:16 AM

Hi,

I am using the below code to fetch data. If I execute the same method more than 10 times then it rejects connection
There is no max connections in the database means the Unlimited connections are allowed at the db.
Is there a way to handle connection pooling because as per my knowledge Object context automatically opens and closes the connection so I dont understand why I am getting this connection problem after 10 number of connection request.

ANY Help will be appreciated. Thanks in adv.

            using (WSFBIZTALKEntities objBizTalkServer = new WSFBIZTALKEntities())
            {
                try
                {
                    var queryBTSServerName = from bizTalkServer in objBizTalkServer.WAM_BTS_Server
                                             where bizTalkServer.Id == 1
                                             select bizTalkServer.Name;
                    return queryBTSServerName.FirstOrDefault();
                }
                catch (Exception ex)
                {
                    throw ex;
                }  
            } 

Happy Coding
 

this is the reason - selva murugan replied to Swapnil Salunke on 08-Dec-08 07:42 AM

Opening a database connection is a resource intensive and time consuming operation. Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. Connection pool manager maintains a pool of open database connections. When a new connection requests come in, the pool manager checks if the pool contains any unused connections and returns one if available. If all connections currently in the pool are busy and the maximum pool size has not been reached, the new connection is created and added to the pool. When the pool reaches its maximum size all new connection requests are being queued up until a connection in the pool becomes available or the connection attempt times out.

Connection pooling behavior is controlled by the connection string parameters. The following are four parameters that control most of the connection pooling behavior:

  • Connect Timeout - controls the wait period in seconds when a new connection is requested, if this timeout expires, an exception will be thrown. Default is 15 seconds.
  • Max Pool Size - specifies the maximum size of your connection pool. Default is 100. Most Web sites do not use more than 40 connections under the heaviest load but it depends on how long your database operations take to complete.
  • Min Pool Size - initial number of connections that will be added to the pool upon its creation. Default is zero; however, you may chose to set this to a small number such as 5 if your application needs consistent response times even after it was idle for hours. In this case the first user requests won't have to wait for those database connections to establish.
  • Pooling - controls if your connection pooling on or off. Default as you may've guessed is true. Read on to see when you may use Pooling=false setting.

try this link - C_A P replied to Swapnil Salunke on 09-Dec-08 01:19 AM

http://www.reflectionit.nl/download.aspx?URL=LinqAndEF.ppt

http://oakleafblog.blogspot.com/2008/10/inq-and-entity-framework-posts-for.html

http://msdn.microsoft.com/en-us/library/cc853327.aspx