You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Fluent Migrator 3.3.2执行超时及RunnerContext过时问题求助

解决Fluent Migrator 3.3.2迁移超时及RunnerContext过时问题

问题描述

使用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.

尝试通过已过时的runner.RunnerContext.Timeout = Timeout.Infinite;设置超时,触发空引用异常:

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

解决方案

在Fluent Migrator 3.x版本中,RunnerContext已被废弃,正确设置命令超时的方式是在构建迁移Runner时通过配置项指定,具体分两种场景:

1. 依赖注入场景(推荐)

如果使用.NET依赖注入框架配置Fluent Migrator,可在服务注册阶段通过WithCommandTimeout方法设置全局超时:

services.AddFluentMigratorCore()
    .ConfigureRunner(rb => rb
        .AddSqlServer()
        .WithGlobalConnectionString("YourConnectionString")
        .WithCommandTimeout(Timeout.Infinite) // 设置无限超时,也可指定具体毫秒数
        .ScanIn(typeof(YourMigrationClass).Assembly).For.Migrations());

2. 手动创建Runner场景

若手动实例化迁移Runner,需通过RunnerOptions配置超时:

var runner = new MigrationRunner(
    new AssemblyMigrationSource(typeof(YourMigrationClass).Assembly),
    new RunnerOptions { CommandTimeout = Timeout.Infinite },
    new SqlServerProcessor(
        new SqlServerConnection("YourConnectionString"),
        new NullAnnouncer(),
        new ProcessorOptions(),
        new SqlServerDbFactory()));

runner.MigrateUp();

关键说明

  • CommandTimeout参数接受毫秒数,Timeout.Infinite表示无超时限制,也可根据实际需求设置具体数值(如300000即5分钟)。
  • 空引用异常的原因是3.3.2版本中RunnerContext已不再被初始化,直接访问会导致null引用,因此必须使用上述替代方案。

内容的提问来源于stack exchange,提问作者Tropin Alexey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 03:25:15