Skip to content

Latest commit

 

History

History
127 lines (96 loc) · 6.64 KB

storage-configure-connection-string.md

File metadata and controls

127 lines (96 loc) · 6.64 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.workload ms.tgt_pltfrm ms.devlang ms.topic ms.date ms.author
Configure a Connection String to Azure Storage | Microsoft Docs
Configure a connection string to an Azure storage account. A connection string includes the information needed to authenticate access to a storage account from your application at runtime.
storage
mmacy
timlt
tysonn
ecb0acb5-90a9-4eb2-93e6-e9860eda5e53
storage
storage
na
na
article
12/12/2016
marsma

Configure Azure Storage Connection Strings

Overview

A connection string includes the authentication information needed to access data in an Azure storage account from your application at runtime. You can configure a connection string to:

  • Connect to the Azure storage emulator.
  • Access a storage account in Azure.
  • Access specified resources in Azure via a shared access signature (SAS).

[!INCLUDE storage-account-key-note-include]

Storing your connection string

Your application will need to access the connection string at runtime in order to authenticate requests made to Azure Storage. You have a few different options for storing your connection string:

  • For an application running on the desktop or on a device, you can store the connection string in an app.config file or a web.config file. Add the connection string to the AppSettings section.
  • For an application running in an Azure cloud service, you can store your connection string in the Azure service configuration schema (.cscfg) file. Add the connection string to the ConfigurationSettings section of the service configuration file.
  • You can also use your connection string directly in your code. For most scenarios, however, we recommend that you store your configuration string in a configuration file.

Storing your connection string within a configuration file makes it easy to update the connection string to switch between the storage emulator and an Azure storage account in the cloud. You only need to edit the connection string to point to your target environment.

You can use the Microsoft Azure Configuration Manager class to access your connection string at runtime regardless of where your application is running.

Create a connection string to the storage emulator

[!INCLUDE storage-emulator-connection-string-include]

See Use the Azure Storage Emulator for Development and Testing for more information about the storage emulator.

Create a connection string to an Azure storage account

To create a connection string to your Azure storage account, use the connection string format below. Indicate whether you want to connect to the storage account through HTTPS (recommended) or HTTP, replace myAccountName with the name of your storage account, and replace myAccountKey with your account access key:

DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey

For example, your connection string will look similar to the following sample connection string:

DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=<account-key>

Note

Azure Storage supports both HTTP and HTTPS in a connection string; however, using HTTPS is highly recommended.

Create a connection string using a shared access signature

[!INCLUDE storage-use-sas-in-connection-string-include]

Creating a connection string to an explicit storage endpoint

You can explicitly specify the service endpoints in your connection string instead of using the default endpoints. To create a connection string that specifies an explicit endpoint, specify the complete service endpoint for each service, including the protocol specification (HTTPS (recommended) or HTTP), in the following format:

DefaultEndpointsProtocol=[http|https];
BlobEndpoint=myBlobEndpoint;
QueueEndpoint=myQueueEndpoint;
TableEndpoint=myTableEndpoint;
FileEndpoint=myFileEndpoint;
AccountName=myAccountName;
AccountKey=myAccountKey

One scenario where you may wish to do specify an explicit endpoint is if you have mapped your Blob storage endpoint to a custom domain. In that case, you can specify your custom endpoint for Blob storage in your connection string, and optionally specify the default endpoints for the other services if your application uses them.

Here are examples of valid connection strings that specify an explicit endpoint for the Blob service:

# Blob endpoint only
DefaultEndpointsProtocol=https;
BlobEndpoint=www.mydomain.com;
AccountName=storagesample;
AccountKey=account-key

# All service endpoints
DefaultEndpointsProtocol=https;
BlobEndpoint=www.mydomain.com;
FileEndpoint=myaccount.file.core.windows.net;
QueueEndpoint=myaccount.queue.core.windows.net;
TableEndpoint=myaccount;
AccountName=storagesample;
AccountKey=account-key

The endpoint value that is listed in the connection string is used to construct the request URIs to the Blob service, and it dictates the form of any URIs that are returned to your code.

Note that if you choose to omit a service endpoint from the connection string, then you will not be able to use that connection string to access data in that service from your code.

Creating a connection string with an endpoint suffix

To create a connection string for storage service in regions or instances with different endpoint suffixes, such as for Azure China or Azure Governance, use the following connection string format. Indicate whether you want to connect to the storage account through HTTP or HTTPS, replace myAccountName with the name of your storage account, replace myAccountKey with your account access key, and replace mySuffix with the URI suffix:

DefaultEndpointsProtocol=[http|https];
AccountName=myAccountName;
AccountKey=myAccountKey;
EndpointSuffix=mySuffix;

For example, your connection string should look similar to the following connection string:

DefaultEndpointsProtocol=https;
AccountName=storagesample;
AccountKey=<account-key>;
EndpointSuffix=core.chinacloudapi.cn;

Parsing a connection string

[!INCLUDE storage-cloud-configuration-manager-include]

Next steps