为什么SqlAzureExecutionStrategy无法处理:错误:19 - 物理连接不可用

Dir*_*oer 14 entity-framework azure azure-sql-database

完全例外:

SqlAzureExecutionStrategy

为什么不由SqlAzureExecutionStrategy处理?特别是因为这发生在VIP掉期期间.

写一个DbExecutionStrategy处理这个的自己是一个好主意,还是我错过了什么?

更新 我从Azure云服务迁移到Azure Web应用程序,我看到此错误的次数严重下降.

rou*_*uen 14

从分析器跟踪中,我们观察到每个查询数据库查询使用相同的连接.这是设计和早期讨论的,即当开发人员明确打开连接时,它告诉EF不要为每个命令打开/重新打开连接.

那肯定听起来不像一般声明.什么探查器跟踪?为什么假设开发人员明确打开连接并处理到EF?在原始问题中我没有看到这样的东西(这不是EF的常见做法).

所以问题仍然没有答案:为什么不由SqlAzureExecutionStrategy处理?编写一个处理这个的DbExecutionStrategy是一个好主意吗?

由于我可以不时在Azure服务中看到此错误,因此我决定对其进行测试.这是我的策略:

public class ExtendedSqlAzureExecutionStrategy : SqlAzureExecutionStrategy
    {
        public ExtendedSqlAzureExecutionStrategy(int maxRetryCount, TimeSpan maxDelay) : base(maxRetryCount, maxDelay) 
        { }

        protected override bool ShouldRetryOn(Exception exception)
        {
            return base.ShouldRetryOn(exception) || IsPhysicalConnectionNotUsableSqlException(exception);
        }

        private bool IsPhysicalConnectionNotUsableSqlException(Exception ex)
        {
            var sqlException = ex as SqlException;
            if (sqlException != null)
            {
                // Enumerate through all errors found in the exception.
                foreach (SqlError err in sqlException.Errors)
                {
                    if (err.Number == 19)
                    {
                        return true;
                    }                    
                }
            }

            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

编辑

好的,所以经过一段时间和日志记录,我可以告诉我的战略基于

if (err.Number == 19)
Run Code Online (Sandbox Code Playgroud)

错的.此错误实际SQLException对象具有ErrorCode = -2146232060Number = -1-我无法找到那些任何文件,所以我决定不再在其基础上的战略.现在我正在尝试琐碎的检查:

public class ExtendedSqlAzureExecutionStrategy : SqlAzureExecutionStrategy
    {
        public ExtendedSqlAzureExecutionStrategy(int maxRetryCount, TimeSpan maxDelay) : base(maxRetryCount, maxDelay) 
        { }

        protected override bool ShouldRetryOn(Exception exception)
        {
            return base.ShouldRetryOn(exception) || IsPhysicalConnectionNotUsableSqlException(exception);
        }

        private bool IsPhysicalConnectionNotUsableSqlException(Exception ex)
        {
            var sqlException = ex as SqlException;
            if (sqlException != null)
            {
                return sqlException.Message.Contains("Physical connection is not usable");
            }

            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

编辑2:

有用.没有更多的Physical connection is not usable错误,也没有RetryLimitExceededException,所以这个错误实际上是暂时的(通过重试可以解决),所以我认为它应该被包含在内SqlAzureExecutionStrategy.