Azure sql database 错误40和SqlAzureExecutionStrategy
我有一个服务结构服务(来宾可执行文件),使用entityframework核心,与SQLAzure对话 我不时看到以下错误: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
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())
一个主要的警告是,目前我正在失去上下文,因此我不知道试图更新/插入哪些数据,因此我不知道它最终是否成功
两个问题:
我看到了这个问题:,感觉很熟悉,但他似乎已经通过调整他的数据库解决了这个问题——我将看看他在做什么,我正在努力使我的代码在数据库出现问题时更具弹性。如果两个数据库事务之间的时间跨度很小,有一个特定版本的EF Core可以缓存查询或请求,因此请更新您的包以确保您使用的是最新的。 检查这些其他链接