如何在aspnetcore/entityframeworkcore中设置命令超时 [英] How to set command timeout in aspnetcore/entityframeworkcore

查看:499
本文介绍了如何在aspnetcore/entityframeworkcore中设置命令超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置命令超时的位置不再与早期版本相同.

但是,我找不到任何地方说明如何更改此内容.

我正在做的是上传非常大的文件,该文件的保存时间超过了默认的30秒.

请注意,我询问的是命令超时,而不是其他问题.

解决方案

如果使用DI容器管理DbContext(即,将DbContext添加到服务集合中),则可以在以下命令中指定命令超时:选项.

在Startup.ConfigureServices中:

services.AddDbContext<YourDbContext>(options => options.UseSqlServer(
    this.Configuration.GetConnectionString("YourConnectionString"),
    sqlServerOptions => sqlServerOptions.CommandTimeout(60))
);

The place where the command timeout is set is no longer the same as earlier versions.

However, I cannot find anywhere that says how to change this.

What I am doing is uploading very large files which takes longer than the default 30 seconds to save.

Note that I ask about Command Timeout, not Migration Timeout as in another question.

解决方案

If you're using the DI container to manage the DbContext (i.e. you're adding the DbContext to the service collection), the command timeout can be specified in the options.

In Startup.ConfigureServices:

services.AddDbContext<YourDbContext>(options => options.UseSqlServer(
    this.Configuration.GetConnectionString("YourConnectionString"),
    sqlServerOptions => sqlServerOptions.CommandTimeout(60))
);

这篇关于如何在aspnetcore/entityframeworkcore中设置命令超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆