Azure sql database 错误40和SqlAzureExecutionStrategy

Azure sql database 错误40和SqlAzureExecutionStrategy,azure-sql-database,entity-framework-core,Azure Sql Database,Entity Framework Core,我有一个服务结构服务(来宾可执行文件),使用entityframework核心,与SQLAzure对话 我不时看到以下错误: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is cor

我有一个服务结构服务(来宾可执行文件),使用entityframework核心,与SQLAzure对话

我不时看到以下错误:

A network-related or instance-specific error occurred while establishing a connection 
to SQL Server. The server was not found or was not accessible. Verify that the 
instance name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
这似乎是暂时的,因为有许多数据库事务在没有错误的情况下发生。当节点繁忙时,这种情况似乎发生得更多

我在启动中添加了代码,以设置EnableRetryOnFailure以设置SqlServerRetryingExecutionStrategy:

services.AddEntityFrameworkSqlServer()
        .AddDbContext<MyDbContext>(options => 
            options.UseSqlServer(_configuration.GetConnectionString("MyDbConnection"),
            o => o.EnableRetryOnFailure()))
services.AddEntityFrameworkSqlServer()
.AddDbContext(选项=>
options.UseSqlServer(_configuration.GetConnectionString(“MyDbConnection”),
o=>o.EnableRetryOnFailure())
一个主要的警告是,目前我正在失去上下文,因此我不知道试图更新/插入哪些数据,因此我不知道它最终是否成功

两个问题:

  • 从表面上看,这看起来不像是错误:40被捕获,但我的理解是,错误40实际上可能是另一个错误(不清楚)。对吗
  • 这真的是一个暂时的问题,还是意味着我有另一个问题
  • 如果没有额外的日志记录(处理),我们是否知道重试策略是否记录了错误,但仍然重试,并且实际上可能已经成功
  • 如果这是一个暂时的错误,但是它没有被默认的执行策略捕获,为什么不呢?将SqlAzureExecutionStrategy细分为包含此错误的子类会产生什么意外后果

  • 我看到了这个问题:,感觉很熟悉,但他似乎已经通过调整他的数据库解决了这个问题——我将看看他在做什么,我正在努力使我的代码在数据库出现问题时更具弹性。

    如果两个数据库事务之间的时间跨度很小,有一个特定版本的EF Core可以缓存查询或请求,因此请更新您的包以确保您使用的是最新的。

    检查这些其他链接