Connection String to an Azure Cloud Storage Account
Notating this because it's a top Google hit and the information is no longer current.
You can configure CloudStorageAccount
via a connection string passed to FromConfigurationSetting()
.
You build a configuration string per below:https://docs.microsoft.com/en-gb/azure/storage/common/storage-configure-connection-string
There's also a helper in the IDE if you right click on the Role.
Reference: Azure Documentation
Connection string to an Azure storage account:
DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey
example:
DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=<account-key>
Connection string to the storage emulator:
config.xml
<appSettings> <add key="StorageConnectionString" value="UseDevelopmentStorage=true" /> </appSettings>DefaultEndpointsProtocol=http;AccountName=testacc1;AccountKey=1gy3lpE7Du1j5ljKiupgKzywSw2isjsdfdsfsdfsdsgfsgfdgfdgfd/YThisv/OVVLfIOv9kQ==;BlobEndpoint=http://127.0.0.1:8440/testacc1;TableEndpoint=http://127.0.0.1:8440/testacc1;QueueEndpoint=http://127.0.0.1:8440/testacc1;
Ex:
<connectionStrings> <add name="AzureStorageAccount" connectionString="DefaultEndpointsProtocol=https;AccountName=testdata;AccountKey=1gy3lpE7Du1j5ljKiupgKzywSw2isjsdfdsfsdfsdsgfsgfdgfdgfd/YThisv/OVVLfIOv9kQ==;"/> </connectionStrings>
But sometimes it won't work and will through the error
An unhandled exception of type 'System.FormatException' occurred in Microsoft.WindowsAzure.Storage.dllAdditional information: No valid combination of account information found.
then please try with below code: tested and working 100%
var accountName = "test2rdsfdg462";var keyValue = "1gy3lpE7Du1j5ljKiupgKzywSfsdfdsfsdfsdfsdfsdfsdqGxd7/YThisv/OVVLfIOv9kQ==";var useHttps = true;var connValid = true;var storageCredentials = new StorageCredentials(accountName, keyValue);var storageAccount = new CloudStorageAccount(storageCredentials, useHttps);var conString = storageAccount.ToString(connValid);CloudStorageAccount sa = CloudStorageAccount.Parse(connString);
If you look in the Azure portal under the storage account in question, and look in the "Access Keys" item in the left-side nav, there it shows you the two provided keys and the entire connection string needed to access the storage account.