“Update-Database” command fails with TimeOut excep

2019-04-18 15:39发布

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 ALTER COLUMN [MyColumn] [nvarchar](2) NULL

And this command fails with TimeOut exception. Tried to setup CommandTimeout i nDbContext constructor without any luck.

Is there any way to disable or setup timeout for Package Manager Console EF commands?

3条回答
\"骚年 ilove
2楼-- · 2019-04-18 16:09

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
    }
}
查看更多
混吃等死
3楼-- · 2019-04-18 16:09

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.

查看更多
走好不送
4楼-- · 2019-04-18 16:26

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.

查看更多
登录 后发表回答