将瞬态故障处理应用程序块与 SQL Azure 一起使用。在此示例中,oCmd.ExecuteReader() 的特定重试逻辑是强制性的,还是由 ReliableSqlConnection 处理?
Using oCmd As New SqlCommand()
strSQL = "SELECT xxxxxx.* FROM xxxxxx"
oCmd.CommandText = strSQL
Using oConn As New ReliableSqlConnection(Cs, retryPolicy)
oConn.Open()
oCmd.Connection = oConn
Using oDR As SqlDataReader = oCmd.ExecuteReader()
If oDR.Read() Then
sb1.Append(oDR("xxxxxx").ToString)
End If
End Using
End Using
End Using
* 更新 *
从下面的响应中,如果我从 ReliableSqlConnect 对象的上下文创建 SqlCommand 对象,我可以期望重试行为也扩展到命令,如本页所述 http://geekswithblogs.net/ScottKlein/archive/2012/ 01/27/understanding-sql-azure-throttling-and-implementing-retry-logic.aspx
“下面的下一个代码示例说明了使用 RetryPolicy 类创建重试策略,指定重试尝试和重试之间的固定时间。然后将此策略应用于 ReliablSqlConnection 作为连接策略和命令策略。”
RetryPolicy myretrypolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(3, TimeSpan.FromSeconds(30));
using (ReliableSqlConnection cnn = new ReliableSqlConnection(connString, myretrypolicy, myretrypolicy))
{
try
{
cnn.Open();
using (var cmd = cnn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM HumanResources.Employee";
using (var rdr = cnn.ExecuteCommand<IDataReader>(cmd))
{
//
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}