2017-04-03 85 views
0

我有一个服务结构服务(客户可执行文件),使用entityframework核心,与sql azure交谈。错误40和SqlAzureExecutionStrategy

不时我看到了以下错误:

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())) 

一个主要的警告,是在我失去语境,所以我不知道什么样的数据正尝试的那一刻要更新/插入,所以我不知道它是否最终成功。

几个问题:

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

我已经看到了这个问题:Sql Connection Error 40 Under Load,而且感觉很熟悉,但他似乎通过调整他的数据库已经解决了它 - 我将看看做什么,我试图让我的代码更具弹性数据库问题的情况。

回答

0

如果两个数据库事务之间的时间间隔很小,EF Core有一定的缓存查询或请求的版本,因此请更新您的软件包以确保您使用的是最新版本。 Query: Threading issues cause NullReferenceException in SimpleNullableDependentKeyValueFactory #5456

检查这些其他环节

  1. https://github.com/aspnet/EntityFramework/issues/5456
  2. https://github.com/aspnet/Security/issues/739
  3. https://github.com/aspnet/EntityFramework/issues/6347
  4. https://github.com/aspnet/EntityFramework/issues/4120
相关问题