EF Code First - Timeout expired. The timeout period elapsed prior to completion

后端 未结 6 1168
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 23:34

Apology for this strangely worded question. I don\'t know what the actual problem is but hopefully someone can give me some insights.

I am getting the following error wh

相关标签:
6条回答
  • 2021-02-07 00:05

    An FYI EF Migrations pull their timeout from a separate configuration:

    public class MyContextConfiguration : DbMigrationsConfiguration<MyContext>
    {
        public MyContextConfiguration()
        {
            CommandTimeout = 900;
        }
    }

    Change the 900 to a something higher, all of the other SQL timeout changes (web.config, etc.) did not do anything, this worked for me.

    0 讨论(0)
  • 2021-02-07 00:07

    For me, the problem was that that migration script took a long time to run (15 minutes).

    This is how I worked around the issue:
    1. Run update-database -script (-force may be necessary)
    2. Copy this SQL script output and run in SQL Server Management Studio

    0 讨论(0)
  • 2021-02-07 00:07

    I ran into this in my production environment because it was producing queries like the ones here: Why does Entity Framework 6 generate complex SQL queries for simple lookups?

    This is actually related to a bug in this version of EF: https://entityframework.codeplex.com/workitem/2083

    They changed the default null semantics from 5 to 6 so I'm guessing you had the same problem I did after upgrading. My machine had a fraction of the data as my remote installation and until I got to production I didn't know I had a performance issue. The queries will often produce a table scan which will time out for larger tables.

    To change it back so that it works like EF5 you have to set:

    DbContextConfiguration.UseDatabaseNullSemantics = true

    See here: http://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbcontextconfiguration.usedatabasenullsemantics(v=vs.113).aspx

    The bug was fixed in EF 6.1 but you still have to set the option above to get simple where conditions.

    0 讨论(0)
  • 2021-02-07 00:13

    In the constructor of Configuration.cs class (in migration Folder) add the property CommandTimeout = Int32.MaxValue;

    0 讨论(0)
  • 2021-02-07 00:15

    I just had the same exact issue, i know this thread is a year old but maybe it will help someone else.

    I was trying to create the database in entity 5 using the Package Manager Console using the connection string below.

    update-database -ConfigurationTypeName My.Project.EF.Migrations.Configuration -ConnectionStringName MyDatabaseDev -ProjectName Project.Name -StartUpProjectName Database.Name

    Each time i ran it i got the error below.

    Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

    To fix it i simply added the -force parameter and it went right through.

    0 讨论(0)
  • 2021-02-07 00:17

    I restarted the SQL Server service (Win7 - Computer Management > Services and Applications > Services)

    0 讨论(0)
提交回复
热议问题