Linq2Sql issues

Nov 16, 2009 at 5:01 PM

Hi everyone!

I performed stress testing of site based on Kigg Framework and at some point (approximately after 15 - 20 minutes) huge amount of errors occurs. Seems that there are problems with opening and closing data connections, which is kinda strange, because DataContext is wrapped into UnitOfWork, so connections disposing should be done automatically. I would really appreciate your solutions or guesses. Here are exceptions that i got from log file:

 

1) Timestamp: 11/16/2009 5:06:23 PM
              Message: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
   at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
   at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
   at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.CompiledQuery.Execute(IProvider provider, Object[] arguments)
   at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues)
   at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance)
   at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.DeferredSource.GetEnumerator()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at System.Data.Linq.Link`1.get_Value()
   at Kigg.DomainObjects.Story.get_HtmlDescription() in D:\Workspace\ASP.NET\boom\LinqToSql\Database.designer.cs:line 1146
   at ASP.views_story_story_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\HostingSpaces\gsmnews\test.gsm-news.net\wwwroot\Views\Story\Story.ascx:line 178
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Control.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 

2) Timestamp: 11/16/2009 5:11:24 PM
Message: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: Invalid attempt to call FieldCount when reader is closed.
at System.Data.SqlClient.SqlDataReader.get_FieldCount()
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderSession`1.GetActiveNames()
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderBase`1.Buffer()
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderSession`1.Buffer()
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderSession`1.CompleteUse()
at System.Data.Linq.SqlClient.SqlConnectionManager.BootUser(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.CompiledQuery.Execute(IProvider provider, Object[] arguments)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.DeferredSource.GetEnumerator()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at System.Data.Linq.Link`1.get_Value()
at Kigg.DomainObjects.Story.get_HtmlDescription() in D:\Workspace\ASP.NET\boom\LinqToSql\Database.designer.cs:line 1146
at ASP.views_story_story_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\HostingSpaces\gsmnews\test.gsm-news.net\wwwroot\Views\Story\Story.ascx:line 178
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


3) Timestamp: 11/16/2009 5:11:25 PM Message: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ObjectDisposedException: Cannot access a disposed object. Object name: 'DataContext accessed after Dispose.'. at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues) at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance) at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.DeferredSource.GetEnumerator() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at System.Data.Linq.Link`1.get_Value() at Kigg.DomainObjects.Story.get_HtmlDescription() in D:\Workspace\ASP.NET\boom\LinqToSql\Database.designer.cs:line 1146 at ASP.views_story_story_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\HostingSpaces\gsmnews\test.gsm-news.net\wwwroot\Views\Story\Story.ascx:line 178 at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


4) Timestamp: 11/16/2009 5:15:20 PM Message: System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.String'. at System.Data.SqlClient.SqlBuffer.get_String() at System.Data.SqlClient.SqlDataReader.GetString(Int32 i) at Read_Story(ObjectMaterializer`1 ) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at System.Linq.Enumerable.d__aa`1.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at Kigg.PagedResult`1..ctor(IEnumerable`1 result, Int32 total) in D:\Workspace\ASP.NET\boom\Core\Helper\PagedResult.cs:line 17 at Kigg.Repository.LinqToSql.BaseRepository`2.BuildPagedResult[T](IEnumerable entities, Int32 total) in D:\Workspace\ASP.NET\boom\LinqToSql\Repository\BaseRepository.cs:line 47 at Kigg.Repository.LinqToSql.StoryRepository.FindNews(Int32 start, Int32 max) in D:\Workspace\ASP.NET\boom\LinqToSql\Repository\StoryRepository.cs:line 175 at Kigg.Repository.DecoratedStoryRepository.FindNews(Int32 start, Int32 max) in D:\Workspace\ASP.NET\boom\Core\Repository\Decorated\DecoratedStoryRepository.cs:line 85 at Kigg.Repository.DecoratedStoryRepository.FindNews(Int32 start, Int32 max) in D:\Workspace\ASP.NET\boom\Core\Repository\Decorated\DecoratedStoryRepository.cs:line 85 at Kigg.Repository.CachingStoryRepository.FindNews(Int32 start, Int32 max) in D:\Workspace\ASP.NET\boom\Core\Repository\Decorated\Caching\CachingStoryRepository.cs:line 121 at Kigg.Web.StoryController.News(Nullable`1 page) in D:\Workspace\ASP.NET\boom\Web\Controllers\StoryController.cs:line 341 at lambda_method(ExecutionScope , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.b__7() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.<>c__DisplayClassc.b__9() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) Category: General Priority: -1 EventId: 0 Severity: Error Title:Unable to cast object of type 'System.DateTime' to type 'System.String'. Machine: LEAF Application Domain: /LM/W3SVC/264/ROOT-4-129028643419756330 Process Id: 43496 Process Name: C:\Windows\SysWOW64\inetsrv\w3wp.exe Win32 Thread Id: 12040 Thread Name: Extended Properties: page - 1 controller - Story action - News

Thanks!

Feb 6, 2013 at 6:05 PM
Yeh, I haved noticed the same thing. Not sure what the cause is.

Did you ever solve your problem?