Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "StorageConnectionString" from ServiceRuntime: FAIL

I connect to a blob store programatically:

string connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
...

My App.Config settings are:

<configuration>
  <appSettings>
    <add key="StorageConnectionString"
         value="DefaultEndpointsProtocol=http;AccountName=ACNAME;AccountKey=MYKEY==" />
  </appSettings>
...

The connection works. However I see the message "Getting "StorageConnectionString" from ServiceRuntime: FAIL" on my local unit tests:

enter image description here

What is the reason for this message and how I can fix it?

like image 617
Miroslav Popov Avatar asked Jun 12 '14 17:06

Miroslav Popov


2 Answers

I had the same problem with Azure Table Storage, but everything works.

Add to your web.config :

<connectionStrings>
    <add name="ConnectionTableAzure" connectionString="DefaultEndpointsProtocol=https;AccountName=[ACCOUNTNAMEHERE];AccountKey=[ACCOUNTKEYHERE];TableEndpoint=[ENDPOINTHERE]"/>
</connectionStrings>

Replace :

storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ConnectionTableAzure"));

By this :

storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["ConnectionTableAzure"].ConnectionString);
like image 120
SoEz Avatar answered Sep 28 '22 09:09

SoEz


The previous solutions works, but I would like to expand more on it.

It replaces values even if the code runs in production, however sometimes you really want to let Azure handle the configuration, while keeping control of your output window while debugging.

I created the following class to help with that.

public static class CloudConfigurationManagerExt
{
    public static string GetSetting(string configurationValue)
    {
#if DEBUG
        return System.Configuration.ConfigurationManager.AppSettings[configurationValue];
#else
        return Microsoft.Azure.CloudConfigurationManager.GetSetting(configurationValue);
#endif
    }
}

then I changed all the calls to CouldConfigurationManager.GetSetting to mine.

From

string connStr = CloudConfigurationManager.GetSetting("Microsoft.AzureBlobStorage.ConnectionString");

To

string connStr = CloudConfigurationManagerExt.GetSetting("Microsoft.AzureBlobStorage.ConnectionString");

and added the setting in the appSetting part of the web.config, or app.config as needed.

web.config

<add key="Microsoft.AzureBlobStorage.ConnectionString" value="YourValueHere" />

As you can see. If you are running in debug mode, it gets the value from the appsetting, else follows the regular path for CloudConfigurationManager.GetSetting

like image 33
Alejandro Gonzalez Avatar answered Sep 28 '22 07:09

Alejandro Gonzalez