“Update-Database” command fails with TimeOut exception

后端 未结 4 1615
南旧
南旧 2021-02-18 19:37

I\'m using EF migrations and have a table with a lot of data. I need to change MaxLength of a concrete column (it hadn\'t length constraints).

ALTER TABLE MyDb A         


        
相关标签:
4条回答
  • 2021-02-18 20:04

    Alternatively script out the change by using

    Update-Database -script
    

    You can then take the script and run it using SQL Management Studio against the database.

    0 讨论(0)
  • 2021-02-18 20:10

    Found solution by myself.

    Since EF5 there is a new property CommandTimeout which is available from DbMigrationsConfiguration

    internal sealed class MyMigrationConfiguration : DbMigrationsConfiguration<MyDbContext>
    {
        public Configuration()
        {
            CommandTimeout = 10000; // migration timeout
        }
    }
    
    0 讨论(0)
  • I just had almost the exact same thing: timeout expired when trying to increase a column length. For me, using update-database had been working just fine an hour ago. The problem turned out to be an open transaction on the database and table I was trying to alter. Once I rolled back that transaction, the update-database command went through without problems.

    0 讨论(0)
  • 2021-02-18 20:19

    In my case the issue was caused by a very large query which timed out in EF but was able to complete in SSMS.

    The answer which suggests Update-Database -script did not work for me, it gave another error message.

    For me, I did the following:

    • Open SSMS
    • Tools > SQL Server Profiler
    • Go back to VS and run Update-Database
    • Watch the Server Profiler
    • You should be able to see the query it times out on
    • Copy that query and run it in SSMS
    • Now re-run Update-Database and that slower part should be fine because the query has already been completed.

    Disclaimer: This might not work for all cases, because it depends on what particular query is slowing you down. For me, it worked.

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