简体   繁体   中英

Entity Framework hangs when I try to get values

My program hangs when it gets values using Entity Framework. Here is my simple code:

LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // it hangs here

It's not an async method. There are solutions about async but I didn't find any solution to fix my problem.

It doesn't respond, it's waiting forever. All my code was running until 2 days ago. I didn't type or do anything and this bug happened (short video is here )

I have tried these things so far:

  • I removed Entity Framework model from my solution and I added it again

  • I created a new program and I used exactly same codes and model (it worked):

     LearningEnglishEntities1 db = new LearningEnglishEntities1(); List<tb_Words> sample = db.tb_Words.ToList(); // It worked
  • I cleaned my solution

  • I typed this code:

     var query = from item in db.tb_Words select item; // It hangs the same way
  • I checked this code is not run by another thread:

     bool query0 = this.InvokeRequired; if (!query0) { LearningEnglishEntities db2 = new LearningEnglishEntities(); List<tb_Words> searchedItems = db2.tb_Words.ToList(); // It still hangs }
  • I changed my Entity Framework 6.0x version to 5.0x but it didn't work.

  • I completely copied all files and pasted to a new project. It ran but it didn't work

  • I restarted Microsoft Distributed Transaction Coordinator Service and checked startup type is Automatically. It didn't work.

Strangely, it works on other projects but it hangs on this project. I haven't found any solution to fix this bug. Do you think what should i do?

Also My Connection String is :

<connectionStrings><add name="LearningEnglishEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-REKGVD4\SQLEXPRESS;initial catalog=LearningEnglish;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

Thank you

After all things, I was able to find a solution but I don't know the reason. Using Entity Framework Code First solved my problem. It is not good for my project but i have to use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM