Click here to Skip to main content
Sign Up to vote bad
good
See more: MySQLentityMVC3
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#">
Posted 25 Jun '12 - 17:40
gavinv421
Edited 1 Jul '12 - 21:16


2 solutions

The error says that that the datareader is in open state else where. first close the datareader and the open it when u want to use it again. It is simlar to connection object.
something like this
//some function
connectionobject.open()
//do some code
sqldatareader dr = cmd.executereader();
dr.open();
//do some code
dr.close();
//some function2
 connectioobject.open();
//do some code
sqldatareader dr1 = cmd.executereader();
dr1.open();
//do some code
dr1.close();
 
This should solve your issue
  Permalink  
Comments
gavinv - 2 Jul '12 - 4:30
thanx, but i'm beginer in MVC, so should you post an extractly code for me? since no SQLDATAREADER in the Designer.cs file.
Arjun YK - 2 Jul '12 - 5:17
If u can send me the coe may be I'll try to solve the issue
gavinv - 2 Jul '12 - 7:37
thanx,maybe i will send code to you later,now i get some code maybe can solve this problem, but the last line i can find what's it,would you explain it or collected it to me? public static void RemoveAllRelatedObjects(EntityObject entity) { if (entity == null) { return; } var relationshipManager = ((IEntityWithRelationships)entity).RelationshipManager; if (relationshipManager == null) { return; } foreach (var re in relationshipManager.GetAllRelatedEnds()) { var enumerator = re.GetEnumerator(); if (enumerator == null) { continue; } var allObject = new List(); while (enumerator.MoveNext()) { allObject.Add((IEntityWithRelationships)enumerator.Current); } foreach(var v in allObject) { re.Remove(v); } MiRelatedEndSetIsLoad.Invoke(re, new object[] {false}); } }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 419
1 Mahesh Bailwal 303
2 CPallini 245
3 Maciej Los 240
4 Aarti Meswania 173
0 Sergey Alexandrovich Kryukov 9,162
1 OriginalGriff 7,179
2 CPallini 3,913
3 Rohan Leuva 3,176
4 Maciej Los 2,588


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid