问题描述
我已实现了以下code写入到Azure数据库处理时,INSERT / UPDATE重试逻辑与指数退避。
I have implemented the following code for handling INSERT/UPDATE retry logic with exponential backoff when writing to an Azure Database.
static SqlConnection TryOpen(this SqlConnection connection)
{
int attempts = 0;
while (attempts < 5)
{
try
{
if (attempts > 0)
System.Threading.Thread.Sleep(((int)Math.Pow(3, attempts)) * 1000);
connection.Open();
return connection;
}
catch { }
attempts++;
}
throw new Exception("Unable to obtain a connection to SQL Server or SQL Azure.");
}
不过,我应该考虑应用重试逻辑我的数据库中读取呢?或将在SqlCommand.CommandTimeout()方法就足够了?我的大部分读取使用以下code被提起:
However should I consider applying retry logic for my database reads as well? Or would the SqlCommand.CommandTimeout() method suffice? Most of my reads are instituted using the following code:
Dim myDateAdapter As New SqlDataAdapter(mySqlCommand)
Dim ds As New DataSet
myDateAdapter.Fill(ds, "dtName")
这是很难知道什么会发生在生产环境中使用Azure的,所以我想现在要做的尽可能多的缓解可能的排序瞬态错误的。
It's hard to know what sort of transient errors will occur in a production environment with Azure so I am trying to do as much mitigation as possible now.
推荐答案
我觉得重试将要在你的一般的Windows Azure SQL数据库操作的一部分。
I think retries are going to be part of your Windows Azure SQL Database operations in general.
而不是实现自定义的解决方案,你看了的?
Rather than implementing a custom solution, have you looked at the transient fault handling application block published by Microsoft Patterns and Practices, specifically for SQL Database?
这篇关于SQL Azure数据库的重试逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!