3

We applied Microsoft's Enterprise Library Transient Fault Handling Block on the Azure Sql connection and commands.

For example,

using(var sqlConnection = new ReliableSqlConnection(_connectionString, _connectionRetry, _commandRetry)
{
    var command = sqlConnection.CreateCommand();
    command.CommandText = "...";
    sqlConnection.Open();

    using(var reader = sqlConnection.ExecuteCommand<SqlDataReader>(command))
    {
        ...
    }
}

It would work for such as command.ExecuteReader(), which is the original call without retry policy. But what if the code uses DataSet and SqlDataAdapter:

using(var sqlConnection = new ReliableSqlConnection(_connectionString, _connectionRetry, _commandRetry)
{
    var command = sqlConnection.CreateCommand();
    command.CommandText = "...";
    sqlConnection.Open();

    // how to convert below codes to right way?
    var adapter = new SqlDataAdapter(command);
    var dataSet = new DataSet();
    adapter.Fill(dataSet);

    // handle dataSet
    ...
}

We are mainly working on some legacy code to add some retry strategy.

Jerry Bian
  • 3,998
  • 6
  • 29
  • 54

1 Answers1

1

Ok, I have found a solution for this:

using(var sqlConnection = new ReliableSqlConnection(_connectionString, _connectionRetry, _commandRetry)
{
    var command = sqlConnection.CreateCommand();
    command.CommandText = "...";
    sqlConnection.Open();

    var dataReader = sqlConnection.ExecuteCommand<SqlDataReader>();
    var dataTable = new DataTable();
    dataTable.Load(dataReader);

    // handle dataTable, in our case the data set only returns one table, so it's ok
    ...
}
Jerry Bian
  • 3,998
  • 6
  • 29
  • 54