Azure SQL Database Repeat Logic

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.

+5
source share
3 answers

I think retries will be part of your operations with your Windows Azure SQL database.

, , , Microsoft Patterns and Practices, SQL Database

+5

SQL Azure . , , , , Azure , .

, , . SQL- , SQL- .

5 SQL Azure 100 000 .

SQL Azure. ADO.NET, - .

Entity Framework, : SQL Azure Entity Framework

+4

SqlConnection SqlCommand, . NuGet.

+1

All Articles