There is already an open DataReader associated with this Connection MySql


I am using Entity framework with .Net to connect to MySql database. When I query the data I get a error saying

There is already an open DataReader associated with this Connection which must be closed first.

[MySqlException (0x80004005): There is already an open DataReader associated with this Connection which must be closed first.]
MySql.Data.MySqlClient.MySqlCommand.CheckState() +246
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +157
MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +47
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +387

[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.]
System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +423
System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +743
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +157
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() +44
1..ctor(IEnumerable`1 collection) +7667702
1 source) +61
edit | flag
William Patrick
Asked on: Jan 10, 2012 at 12:51AM

1 Answers


There are two possibilities to this error:

1.Your connection is not closed, if you are sure that it is not the issue then follow on to the next possibility

2.It may be possible that the entity framework is not able to convert null datetime into default values. Please try adding the parameter in the connection string use use to connect

Convert Zero Datetime=True;Allow Zero Datetime=True;Allow User Variables=True

So your connection string should look like

    add name="demotestEntities" connectionString="metadata=res://*/Models.MySQLModel.csdl|res://*/Models.MySQLModel.ssdl|res://*/Models.MySQLModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=homeserver;user 
id=databaseid;password=password;persist security info=True;database=demotest;Convert Zero Datetime=True;Allow Zero Datetime=True;Allow User Variables=True""
providerName="System.Data.EntityClient" />
edit | flag
Gokul A
Answered on: Jan 10, 2012 at 1:04AM

Post your Answer


Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags