Click here to Skip to main content
15,893,487 members

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

gavinv asked:

Open original thread
When i run my MVC(C#,use entity Framework+MySql) project, it show that:There is already an open DataReader associated with this Connection which must be closed first. And the error code is:
[assembly: EdmRelationshipAttribute("blogModel", "cid", "cls", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(blog.Models.cls), "news", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(blog.Models.news), true)] [assembly: EdmRelationshipAttribute("blogModel", "uid", "users", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(blog.Models.users), "news", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(blog.Models.news), true)]
[XmlIgnoreAttribute()]     [SoapIgnoreAttribute()]     [DataMemberAttribute()]     [EdmRelationshipNavigationPropertyAttribute("blogModel", "cid", "cls")]     public cls cls     {         get         {             return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<cls>("blogModel.cid", "cls").Value;         }         set         {             ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<cls>("blogModel.cid", "cls").Value = value;         }     }     /// <summary>     /// 没有元数据文档可用。     /// </summary>     [BrowsableAttribute(false)]     [DataMemberAttribute()]     public EntityReference<cls> clsReference     {         get         {             return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<cls>("blogModel.cid", "cls");         }         set         {             if ((value != null))             {                 ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<cls>("blogModel.cid", "cls", value);             }         }     }      /// <summary>     /// 没有元数据文档可用。     /// </summary>     [XmlIgnoreAttribute()]     [SoapIgnoreAttribute()]     [DataMemberAttribute()]     [EdmRelationshipNavigationPropertyAttribute("blogModel", "uid", "users")]     public users users     {         get         {             return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<users>("blogModel.uid", "users").Value;         }         set         {             ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<users>("blogModel.uid", "users").Value = value;         }     }     /// <summary>     /// 没有元数据文档可用。     /// </summary>     [BrowsableAttribute(false)]     [DataMemberAttribute()]     public EntityReference<users> usersReference     {         get         {             return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<users>("blogModel.uid", "users");         }         set         {             if ((value != null))             {                 ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<users>("blogModel.uid", "users", value);             }         }     }      #endregion 

THis code is in the model file xx.Designer.cs,I want to know how to end the GetRelateReference or close DataReader, there no DataReader in xx.Designer.cs. and when i add MultipleActiveResultSets=true to connection string in web.config, i try again, it show me: The format of the initialization string does not meet specifications, how i can fix this problem?
/// 请使用应用程序配置文件的"blogEntities"部分中的连接字符串初始化新 blogEntities 对象。     ///      public blogEntities() : base("name=blogEntities", "blogEntities")     {         this.ContextOptions.LazyLoadingEnabled = true;         OnContextCreated();     }      /// <summary>     /// 初始化新的 blogEntities 对象。     /// </summary>     public blogEntities(string connectionString) : base(connectionString, "blogEntities")     {         this.ContextOptions.LazyLoadingEnabled = true;         OnContextCreated();     }      /// <summary>     /// 初始化新的 blogEntities 对象。     /// </summary>     public blogEntities(EntityConnection connection) : base(connection, "blogEntities")     {         this.ContextOptions.LazyLoadingEnabled = true;         OnContextCreated();     }      #endregion <pre lang="c#">
Tags: Entity Framework, MySQL, MVC3

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900