I used the following code to handle exponentially INSERT / UPDATE repetition logic 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.");
}
However, should I consider using repeat logic to read my database? Or maybe SqlCommand.CommandTimeout () is enough? Most of my readings are entered using the following code:
Dim myDateAdapter As New SqlDataAdapter(mySqlCommand)
Dim ds As New DataSet
myDateAdapter.Fill(ds, "dtName")
It is difficult to understand what temporary errors will occur in a production environment with Azure, so I am trying to do as much mitigation as possible.
QFDev source
share