Connection String to an Azure Cloud Storage Account
Asked Answered
U

4

33

How do I make a connection string to a cloud storage account so I can access tables, blobs, and queues? Sample code appreciated.

Unseemly answered 26/2, 2010 at 0:21 Comment(0)
F
25

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.

Fictile answered 26/5, 2020 at 2:32 Comment(0)
H
16

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://learn.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.

Heliometer answered 16/8, 2011 at 17:0 Comment(0)
H
16

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;Accoun‌​tKey=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.dll

Additional 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);
Hurlburt answered 10/3, 2017 at 12:33 Comment(0)
H
13

Microsoft has a nice guide called Connect an app to Azure Storage that goes through everything you need.

Description:

Create a simple application and add configuration, client library references, and code to connect it to Azure Storage.

https://learn.microsoft.com/en-us/learn/modules/connect-an-app-to-azure-storage/

Step 7 there is Connect to your Azure storage account

Connection strings example:

DefaultEndpointsProtocol=https;AccountName={your-storage};
   AccountKey={your-access-key};
   EndpointSuffix=core.windows.net

The REST endpoint is a combination of your storage account name, the data type, and a known domain. For example:

Data type Example endpoint
Blobs https://[name].blob.core.windows.net/
Queues https://[name].queue.core.windows.net/
Table https://[name].table.core.windows.net/
Files https://[name].file.core.windows.net/

https://learn.microsoft.com/en-us/learn/modules/connect-an-app-to-azure-storage/7-connect-to-your-azure-storage-account

To get a connection string I usually follow @user3459730 example and copy it from Azure Portal. Go to Storage account -> Access keys, click on Show keys and copy the Connection string.

enter image description here

Houghton answered 20/5, 2022 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.