我已经实现了以下代码,用于在写入Azure数据库时处理具有指数退避的INSERT/UPDATE重试逻辑。SQL Azure数据库重试逻辑
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()方法是否足够?我大部分的读是使用下面的代码提起:
Dim myDateAdapter As New SqlDataAdapter(mySqlCommand)
Dim ds As New DataSet
myDateAdapter.Fill(ds, "dtName")
很难知道会发生在生产环境中使用Azure的,所以我想现在要做的尽可能多的缓解尽可能什么样的瞬态错误的。
我正在调查这个。 TFH块是否会提供有关连接丢失原因的详细信息? – QFDev 2013-03-10 11:33:27