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

  • Question

  • 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 line is:

    get
                {
                    return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<users>("blogModel.uid", "users").Value;
                }
                set

    would somebody help me to fixed it? Thanks a lot

    Sunday, June 24, 2012 5:03 AM

All replies

  • get
                {
                    return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<users>("blogModel.uid", "users").Value;
                }
                set

    this is in the xx.Designer.cs

    Sunday, June 24, 2012 5:07 AM
  • Please refer to this MSDN example about IEntityWithRelationships Interface http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.ientitywithrelationships%28v=vs.90%29.aspx

    A highlight from http://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.80%29.aspx

    Note that while a DataReader is open, the Connection is in use exclusively by that DataReader. You cannot execute any commands for the Connection, including creating another DataReader, until the original DataReader is closed.

    Hope this helps.

    Sunday, June 24, 2012 5:43 AM
  • Thanx for your reply, i know have to close DataReader,but  where it was open? which name of the DataReader I should close? I can't found any DataReader in that file. Would you please point it out for me?
    Sunday, June 24, 2012 7:25 AM
  • Please do a small proj and share with us via SkyDrive or something else. So we can go through the case.
    Sunday, June 24, 2012 9:54 AM