I'm developing MVC application. Infragistics jQuery grid (version 3.12.1.2049) is used for presentation. Entity Framework 4.1.0.0 and Devart dotConnect for Oracle 7.1.40 is is used for data access.
Data access code is based on System.Data.Entity.DbContext. Entity classes have System.Data.Entity.DbSet<TEntity> types.
Connection pooling is used and "Max Pool Size" is set to 5 in connection string.
Application works, reads data from database, displays it in grid, but after 5 requests an exception is raised: "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."
I have found out that somewhere connection is not closed.
There are following steps
1.Connection is opened
2.Statement is executedSELECT "top".ACCOUNT_ID,"top".IBAN,"top".NAME,"top".OPENED,"top".CLOSEDFROM ( SELECT "Extent1".ACCOUNT_ID, "Extent1".IBAN, "Extent1".NAME, "Extent1".OPENED, "Extent1".CLOSED FROM schema.view "Extent1" ORDER BY "Extent1".ACCOUNT_ID ASC) "top"WHERE ROWNUM <= 1
3.Statement is executedSELECT "GroupBy1".A1 AS C1FROM ( SELECT Count(1) AS A1 FROM Schema.view "Extent1") "GroupBy1" is executed
4.Statement is executedSELECT "Extent1".ACCOUNT_ID,"Extent1".IBAN,"Extent1".NAME,"Extent1".OPENED,"Extent1".CLOSEDFROM Schema.view "Extent1"ORDER BY "Extent1".ACCOUNT_ID ASC
5.Connection is not closed and is not returned to Connection pool
New call opens new connection.
using Infragistics.Web.Mvc;namespace disw.Controllers{ public class SaskaitosController : DisBaseController { public ActionResult Perziura() { ViewBag.Title = "Accounts"; var d = Db.Accounts .OrderBy(o => o.AccountID); return View(d); } }}
Where Db is DbContext object.
@model IQueryable<diswBL.DisModel.Account>@using Infragistics.Web.Mvc@using diswBL.DisModel@section Header{<script src="@Url.Content("~/Scripts/ig/infragistics.loader.js")" type="text/javascript"></script>@(Html.Infragistics() .Loader() .ScriptPath(Url.Content("~/Scripts/ig/")) .CssPath(Url.Content("~/Content/ig/")) .Render())}<h2>@ViewBag.Title</h2>@section Grid{@(Html.Infragistics().Grid(Model).ID("igAccounts") .AutoGenerateColumns(false) .Columns(col => { col.For(x => x.ACCOUNT_ID).HeaderText("ID").DataType("decimal"); col.For(x => x.IBAN).HeaderText("Account IBAN"); col.For(x => x.NAME).HeaderText("Account Name"); col.For(x => x.OPENED).HeaderText("Opened").DataType("date").Format("dateTime"); col.For(x => x.CLOSED).HeaderText("Closed").DataType("date").Format("dateTime"); }) .Features(features => { features.Paging().Type(OpType.Local).PageSize(10); features.Sorting().Mode(SortingMode.Multiple).Type(OpType.Local); features.Filtering().Mode(FilterMode.Advanced).Type(OpType.Local); features.Selection().Mode(SelectionMode.Row).MultipleSelection(true); }) .Height("500px").Width("100%").DataBind().Render())}
Thank you for advice.
After several tests I have found out that I need to explicitly define pooling options in my connection string.
For example: Pooling=true;Max Pool Size=5
With these options set everything works as expected - connection is taken from the pool, SELECT statement is executed, connection is closed and returned to the pool.
Hi,
we aren't handling any db connections in the MVC wrapper code. the grid is agnostic of the underlying data framework. we are working with the IQueryable API only. I would check somewhere in your application logic, maybe there is some code that's causing this error.
you can have a look at the following article:
http://stephenwalther.com/archive/2008/08/20/asp-net-mvc-tip-34-dispose-of-your-datacontext-or-don-t.aspx
Thanks,
Angel