Azure SQL MultipleActiveResultSets

Azure SQL MultipleActiveResultSets,azure,asp.net-core,.net-core,azure-sql-database,azure-web-app-service,Azure,Asp.net Core,.net Core,Azure Sql Database,Azure Web App Service,出于某些原因,Azure SQL似乎没有在我的dotnet core应用程序的连接字符串中使用MultipleActiveResultSets=True 我的应用程序连接字符串如下所示 Server=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;User ID=xxx;Password=xxxxx;MultipleActiveResultSets=True;Encrypt=True;" services.AddDbC

出于某些原因,Azure SQL似乎没有在我的dotnet core应用程序的连接字符串中使用MultipleActiveResultSets=True

我的应用程序连接字符串如下所示

    Server=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;User ID=xxx;Password=xxxxx;MultipleActiveResultSets=True;Encrypt=True;"
    services.AddDbContext<Models.Database.DBContext>();
我仍然不断地犯这个错误

    A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.
当使用异步方法时,我所有的代码都在等待,所以我不知道还能做什么,因为这段代码与本地sql一起工作

我在DbContext中使用DI,并添加如下服务

    Server=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;User ID=xxx;Password=xxxxx;MultipleActiveResultSets=True;Encrypt=True;"
    services.AddDbContext<Models.Database.DBContext>();
services.AddDbContext();
任何帮助都将不胜感激

使现代化 问题出在我的Startup.cs上。我错过了。我有一个调用dbcontext的方法,但我从不等待结果。没有从IDE中看到任何错误,因为它通常会警告您没有等待异步方法。使用等待更新了该方法,并添加了OnTokenValidated=async上下文。现在一切都好了。

这个

在上一个操作之前,在此上下文上启动了第二个操作 完整的。任何实例成员都不能保证线程安全

是EF错误,而不是SQL Server错误。因此,
MultipleActiveResultSets
是不相关的

当使用异步方法时,我所有的代码都在等待。我在DbContext中使用DI


因此,您的DI可能允许在请求之间共享DbContext实例

可能谢谢,我看了这篇文章,但仍然没有解决问题。谢谢你的回复。我怎样才能阻止它在请求之间共享?没关系。我发现了问题。再次感谢。将更新我的问题