Bug #54132 EF Association "DataReader must be closed first" EntityCommandExecutionException
Submitted: 1 Jun 2010 9:37 Modified: 7 Jan 2011 17:01
Reporter: Ivan Zlatev Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.3.2 OS:Windows (XP)
Assigned to: Assigned Account CPU Architecture:Any
Tags: .net

[1 Jun 2010 9:37] Ivan Zlatev
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.
[19 Jul 2010 18:48] Vladislav Vaintroub
Hello Ivan,
can you upload your project (as .zip file)?
Thanks!
[19 Aug 2010 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[8 Jan 2011 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".