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:
What is the reason for this message and how I can fix it?
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With