Search code examples
c#azureazure-table-storageretrypolicy

Error in Configuring Azure Storage Account after using Retry Policies


This is my code to Configure Azure Storage Account

public CloudTableClient ConfigureStorageAccount()
{
        var storageCred = new StorageCredentials(ConfigurationManager.AppSettings["SASToken"]);

        CloudTableClient = new CloudTableClient(
                        new StorageUri(new Uri(ConfigurationManager.AppSettings["StorageAccountUri"])), storageCred);



        var backgroundRequestOption = new TableRequestOptions()
        {
            // Client has a default exponential retry policy with 4 sec delay and 3 retry attempts
            // Retry delays will be approximately 3 sec, 7 sec, and 15 sec
            MaximumExecutionTime = TimeSpan.FromSeconds(30),
            // PrimaryThenSecondary in case of Read-access geo-redundant storage, else set this to PrimaryOnly
            LocationMode = LocationMode.PrimaryThenSecondary,


        };

        CloudTableClient.DefaultRequestOptions = backgroundRequestOption;

        return CloudTableClient;
}

When I specify backgroundRequestOption I am getting an error The Uri for the target storage location is not specified. Please consider changing the request's location mode.

When I don't specify backgroundRequestOption I don't get any error. Where do I need to specify this URI?


Solution

  • You need to specify both PrimaryUri and SecondaryUri if LocationMode.PrimaryThenSecondary is chosen.