gpt4 book ai didi

asp.net-core - EF Core 间歇性错误 : The connection does not support MultipleActiveResultSets

转载 作者:行者123 更新时间:2023-12-02 18:46:42 27 4
gpt4 key购买 nike

我有一个使用 EF Core 的 ASP.Net Core 应用程序。

我使用 ASP.Net Identity 并为我的应用程序的实体共享相同的 DBContext。

我已将 Azure SQL 数据库的连接字符串设置为 MultipleActiveResultSet=True。

它可以工作一两天,但最终会失败并出现错误:

The connection does not support MultipleActiveResultSets.

我不认为 MARS 是真正的问题,因为它在启动的前两天一直有效。

我正在使用 ASP.Net Core 的内置 DI 来设置我的 DbContext。

services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(appDbContextConnectionString));

我的理解是,上面 DbContext 的默认生命周期是 Transient(每个 Web 请求)。

是否可以与 ASP.Net Identity 共享相同的 DBContext,还是应该为我的应用程序实体拥有一个单独的 DBContext,指向同一个数据库?

我不知道这是 EF Core、ASP.Net Core 还是 SQL Azure 配置的问题。

最佳答案

我有一个类似的问题,我发现问题是我在我的方法前面错过了一个await语句。

FetchStuffFromDBAsync();

成为:

await FetchStuffFromDBAsync();

问题就解决了。

关于asp.net-core - EF Core 间歇性错误 : The connection does not support MultipleActiveResultSets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46033645/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com