The connection does not support MultipleActiveResultSets

Posts   
 
    
MPR Tech
User
Posts: 2
Joined: 06-Aug-2021
# Posted on: 06-Aug-2021 21:17:49   

In an ASP.Net WebForms application that we have taken over, we are replacing all of the hodge-podge of data access methods with a Data Access Layer generated using LLBLGenPro. We are using Self Servicing and Net Standard 2.1. Everything has been working fine until recently; we have started getting this errors randomly throughout the application.

The connection does not support MultipleActiveResultSets. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The connection does not support MultipleActiveResultSets.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The connection does not support MultipleActiveResultSets.]
   System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) +1646631
   System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) +91
   System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) +274
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +119
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +65
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +170
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +43
   System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12
   SD.LLBLGen.Pro.ORMSupportClasses.<>c__DisplayClass12_0.<Execute>b__0() +17
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.TagAndExecuteCommand(Func`1 toExecute) +189
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +125

[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: The connection does not support MultipleActiveResultSets.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.]
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +325
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformExecuteSingleRowRetrievalQuery(IRetrievalQuery queryToExecute, CommandBehavior behavior) +13
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteSingleRowRetrievalQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction, IEntityFields fieldsToFill, IFieldPersistenceInfo[] fieldPersistenceInfos) +195
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformFetchEntityAction(IEntity entityToFetch, ITransaction containingTransaction, IPredicateExpression selectFilter, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields) +391
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.FetchExisting(IEntity entityToFetch, ITransaction containingTransaction, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields) +51
   Foo.DAL.Core.EntityClasses.TimezoneEntity.Fetch(Int32 timeZoneId, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields) +141
   Foo.DAL.Core.EntityClasses.PersonEntity.<GetSingleTimeZone>b__74_0(TimezoneEntity e) +34
   SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.PerformSingleEntityLazyLoading(String navigator, Boolean forceFetch, Boolean returnNewIfNotFound, Func`2 fetchFunc) +325
   Foo.DAL.Core.EntityClasses.PersonEntity.GetSingleTimeZone(Boolean forceFetch) +72
   Foo.DAL.Core.EntityClasses.PersonEntity.get_TimeZone() +14
   Foo.Legacy.incnavleft1.Page_Load(Object sender, EventArgs e) in D:\a\1\s\EBD_64\admin\incnavleft.ascx.vb:10
   System.Web.UI.Control.OnLoad(EventArgs e) +97
   System.Web.UI.Control.LoadRecursive() +61
   System.Web.UI.Control.LoadRecursive() +134
   System.Web.UI.Control.LoadRecursive() +134
   System.Web.UI.Control.LoadRecursive() +134
   System.Web.UI.Control.LoadRecursive() +134
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 07-Aug-2021 09:30:05   

You use a Transaction object that's shared among code, or share entity instances among requests? Selfservicing should open a connection when it needs, unless you use a transaction object and add the entity to it, it's then using the connection of the transaction object. It looks like a connection is currently in use for fetching and you execute another query over the same connection. This doesn't happen in the same thread with the same objects, but if you share objects across requests multiple threads can utilize the same connection which could result in this behavior.

You didn't post any code, please provide code where this goes wrong.

Frans Bouma | Lead developer LLBLGen Pro