I have an issue that happens randomly on our servers. After several calls to Kentico database through the Kentico API CustomTableItemProvider
and ObjectQuery<CustomTableItem>
we receive an exception and the connection to database is blocked.
Kentico assemblies are referenced by an ASP.Net Web API project.
Kentico version: v9.0.17
Initiailzation function:
public bool Init()
{
var physicalPath = ConfigurationManager.AppSettings["KenticoPhysicalPath"];
CMS.Base.SystemContext.WebApplicationPhysicalPath = physicalPath;
return CMS.DataEngine.CMSApplication.Init();
}
Sample Data Access Code:
private List<EventInfo> Get(int emirateID, DateTime startDate, DateTime endDate)
{
return CustomTableItemProvider.GetItems("RYD.Event")
.Source(s => s.Join(new QuerySourceTable("RYD_EventCategory"), "RYD_Event.CategoryID", "EventCategoryID"))
.WhereEquals("RYD_Event.IsDeleted", false)
.WhereEquals("EmirateID", emirateID)
.WhereGreaterOrEquals("EventDate", startDate)
.WhereLessOrEquals("EventDate", endDate)
.Columns("EventID", "EventTitle", "RYD_Event.CategoryID", "RYD_EventCategory.CategoryTitle",
"EventContent", "EventDate", "EventImage", "EventImageID", "EventLocation")
.ResultList(this.Map);
}
and I got this exception
Event ID:
5017
Event type:
Error
Event time:
5/4/2016 10:53:08 AM
Source:
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection
Event code:
b3771c45-e374-4923-be21-00d46e70d525
User ID:
65
User name:
public
IP address:
192.168.87.25
Description:
Message: 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.
Exception type: System.InvalidOperationException
Stack Trace:
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at CMS.DataEngine.AbstractDataConnection.Open()
at CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query)
at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query)
at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query, Int32& totalRecords)
at CMS.DataEngine.DataQueryBase1.GetDataFromDBInternal()
at CMS.DataEngine.DataQueryBase1.GetDataFromDB()
at CMS.DataEngine.DataQueryBase1.GetData()
at CMS.DataEngine.DataQueryBase1.get_Result()
at CMS.DataEngine.ObjectQueryBase2.GetResults(IDataQuery query, Int32& totalRecords)
at CMS.DataEngine.DataQueryBase1.GetDataFromDB()
at CMS.DataEngine.DataQueryBase1.GetData()
at CMS.DataEngine.ObjectQueryBase2.GetData()
at CMS.DataEngine.DataQueryBase1.get_Result()
at CMS.DataEngine.ObjectQueryBase2.EnsureTypedResult()
at CMS.DataEngine.ObjectQueryBase2.System.Collections.IEnumerable.GetEnumerator()
at CMS.DataEngine.EnumerableWrapper1..GetEnumerator>d__0.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source)
at System.Linq.EnumerableExecutor1.ExecuteBoxed()
at CMS.DataEngine.CMSQueryProvider1.Execute[TResult](Expression expression)
at RYD.IPad.Data.Kentico.IpadApiSessionRepository.GetSession(String pTokenHash)
Machine name:
TE1-EFD-WV-IS01
Event URL:
/api/v1/events/1437
URL referrer:
User agent:
Riyadah/1.1 CFNetwork/758.2.8 Darwin/15.0.0