Fluent 迁移器引发超时异常

Fluent migrator throws timout exception

提问人:Tropin Alexey 提问时间:2/9/2023 更新时间:2/9/2023 访问量:368

问:

我使用 Fluent migrator 3.3.2,它在其中一个数据库上抛出错误:

The error was Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

我一直在寻找如何设置超时选项,并发现这篇文章 https://github.com/fluentmigrator/fluentmigrator/discussions/1472

但是被标记为过时,并且没有评论我必须使用什么来代替。如果我尝试使用它,那么就会出错:runner.RunnerContextrunner.RunnerContext.Timeout = Timeout.Infinite;

Migration exception: "Object reference not set to an instance of an object."

在谷歌中找不到任何内容

C# asp.net-web-api .net-6.0 fluent-migrator

评论


答:

0赞 Tropin Alexey 2/9/2023 #1

您可以设置依赖项注入的全局超时

var serviceProvider = new ServiceCollection()
    .AddFluentMigratorCore()
    .ConfigureRunner(rb => rb
        .AddSqlServer()
        //here
        .WithGlobalCommandTimeout(TimeSpan.FromSeconds(120))
        .WithGlobalConnectionString(tenant.ConnectionString)
        .ScanIn(typeof(ApplicationDbContext).Assembly).For.Migrations())
    .Configure<RunnerOptions>(opt => { opt.Tags = new[] { tenant.Id }; })
    .AddLogging(lb => lb.AddFluentMigratorConsole())
    .AddLogging(lb => lb.AddSerilog())
    .BuildServiceProvider(validateScopes: false);