【问题标题】:Error 40 and SqlAzureExecutionStrategy错误 40 和 SqlAzureExecutionStrategy
【发布时间】:2017-04-03 20:04:25
【问题描述】:

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

我有时会看到以下错误:

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,感觉很熟悉,但他似乎通过调整他的数据库解决了这个问题——我会考虑这样做,我试图让我的代码在数据库问题的案例。

【问题讨论】:

    标签: azure-sql-database entity-framework-core


    【解决方案1】:

    如果两个数据库事务之间的时间跨度非常小,则某个版本的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2019-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多