c# - 应该允许重试哪些 SQL 错误代码?

标签 c# error-handling sql-server-2014 high-availability

我们有一个 SQL Server 2014 AlwaysOn 可用性组,我们通过标准 C# SqlConnection 对象连接到该组。我们希望捕获手动或自动触发故障转移时发生的异常,并在等待一段时间后重试该命令。

我们不想重试每条失败的命令,只想重试因故障转移而失败的事务。

Microsoft 是否提供我们可以检查的错误代码列表(或某处有列表)?

最佳答案

Microsoft 已经为 Azure 构建了一个 transient 错误检测策略,用于 transient 故障处理应用程序 block 。

The Transient Fault Handling Application Block (Topaz) makes your application more robust by providing the logic for handling transient faults. It does this in two ways.

First, the block includes logic to identify transient faults for a number of common cloud-based services in the form of detection strategies. These detection strategies contain built-in knowledge that is capable of identifying whether a particular exception is likely to be caused by a transient fault condition.

他们已经确定了表明暂时性故障的 sql 错误代码。虽然它是针对云(针对 Azure Sql Server)的,但我们已在我们自己的本地环境中成功使用了它。

你可以看看他们的代码并提取你可以检查的sql代码:

https://github.com/Dixin/EnterpriseLibrary.TransientFaultHandling.Core/blob/master/Source/TransientFaultHandling.Data.Core/SqlDatabaseTransientErrorDetectionStrategy.cs

关于c# - 应该允许重试哪些 SQL 错误代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40798934/

相关文章:

c# - 为什么 C# 在实现接口(interface)时不允许继承返回类型

c# - 是否可以在 C# 中的运行时创建/执行代码?

python - 当我捕捉到异常时,如何获取上一帧的类型、文件和行号?

r - R Markdown中的错误(二进制运算符的非数字参数)

c# - SQL Server 为数据库中的每个表添加一个唯一标识符

c# - Java 的 ThreadPoolExecutor 等同于 C#?

c# - 删除文件夹的内容而不是文件夹本身?

exception - Azure数据工厂复制事件错误记录异常处理

sql-server - 根据搜索文本删除父子记录

entity-framework - Entity Framework 'Update Model from Database'在基类和子类之间重新创建关联