Bug #54132 EF Association "DataReader must be closed first" EntityCommandExecutionException
Description:
I am trying to use the .NET connector latest 6.2.3 Beta with VS2010 and Entity Framework 4.0 and I get an EntityCommandExecutionException in the following setup:
I have two tables which have no Primary - Foreign Key association between them in the database (not up to me at this point), so instead I have created one by hand in the Entity Framework designer (right click on a table -> New -> Association). However when I try to use it e.g via:
foreach (var project in Entities.Projects)
Console.WriteLine (project.Phases.Count);
where the "Phases" property expresses the relationship between the Project table and the Phases table (one to many) I get:
System.Data.EntityCommandExecutionException was unhandled by user code
Message=An error occurred while executing the command definition. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
at System.Data.Objects.DataClasses.EntityCollection`1.Load(List`1 collection, MergeOption mergeOption)
at System.Data.Objects.DataClasses.EntityCollection`1.Load(MergeOption mergeOption)
at System.Data.Objects.DataClasses.RelatedEnd.Load()
at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
at System.Data.Objects.DataClasses.EntityCollection`1.GetEnumerator()
... ASP.NET lines here omitted...
InnerException: MySql.Data.MySqlClient.MySqlException
Message=There is already an open DataReader associated with this Connection which must be closed first.
Source=MySql.Data
ErrorCode=-2147467259
Number=0
StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
InnerException:
How to repeat:
1. Create two tables e.g. Project with an Id and Phase with an Id and a ProjectId column
2. Import in Entity Framework
3. Create an Association one to many Project - Phase (one project - many phases)
4. Try to use the association programatically.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: I am trying to use the .NET connector latest 6.2.3 Beta with VS2010 and Entity Framework 4.0 and I get an EntityCommandExecutionException in the following setup: I have two tables which have no Primary - Foreign Key association between them in the database (not up to me at this point), so instead I have created one by hand in the Entity Framework designer (right click on a table -> New -> Association). However when I try to use it e.g via: foreach (var project in Entities.Projects) Console.WriteLine (project.Phases.Count); where the "Phases" property expresses the relationship between the Project table and the Phases table (one to many) I get: System.Data.EntityCommandExecutionException was unhandled by user code Message=An error occurred while executing the command definition. See the inner exception for details. Source=System.Data.Entity StackTrace: at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption) at System.Data.Objects.DataClasses.EntityCollection`1.Load(List`1 collection, MergeOption mergeOption) at System.Data.Objects.DataClasses.EntityCollection`1.Load(MergeOption mergeOption) at System.Data.Objects.DataClasses.RelatedEnd.Load() at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad() at System.Data.Objects.DataClasses.EntityCollection`1.GetEnumerator() ... ASP.NET lines here omitted... InnerException: MySql.Data.MySqlClient.MySqlException Message=There is already an open DataReader associated with this Connection which must be closed first. Source=MySql.Data ErrorCode=-2147467259 Number=0 StackTrace: at MySql.Data.MySqlClient.MySqlCommand.CheckState() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) InnerException: How to repeat: 1. Create two tables e.g. Project with an Id and Phase with an Id and a ProjectId column 2. Import in Entity Framework 3. Create an Association one to many Project - Phase (one project - many phases) 4. Try to use the association programatically.