Click here to Skip to main content
11,416,194 members (60,672 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MySQL entity MVC3
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 18:40pm
gavinv421
Edited 1-Jul-12 22:16pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
v2
Comments
gavinv at 2-Jul-12 4:30am
   
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 at 2-Jul-12 5:17am
   
If u can send me the coe may be I'll try to solve the issue
gavinv at 2-Jul-12 7:37am
   
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
0 Sergey Alexandrovich Kryukov 9,270
1 OriginalGriff 7,512
2 Maciej Los 3,710
3 Abhinav S 3,324
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web04 | 2.8.150427.4 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100