连接字符串到Azure云存储帐户

时间:2010-02-26 00:21:56

标签: azure azure-storage-account

如何创建连接字符串到云存储帐户,以便我可以访问表,blob和队列?示例代码赞赏。

3 个答案:

答案 0 :(得分:9)

请注意这一点,因为这是Google的热门搜索,而且信息不再是最新信息。

您可以通过传递给CloudStorageAccount的连接字符串配置FromConfigurationSetting()

您可以按以下方式构建配置字符串: https://docs.microsoft.com/en-gb/azure/storage/common/storage-configure-connection-string

如果右键单击角色,IDE中还有一个帮助程序。

答案 1 :(得分:5)

如果您在相关存储帐户下的Azure门户中查看,并在左侧导航栏中的“访问密钥”项中查看,它将为您显示提供的两个密钥以及访问数据库所需的整个连接字符串。存储帐户。

答案 2 :(得分:1)

参考:Azure Documentation

Azure存储帐户的连接字符串:

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

<强> 例如:

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

存储模拟器的连接字符串:

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;

例如:

 <connectionStrings>      

    <add name="AzureStorageAccount" connectionString="DefaultEndpointsProtocol=https;AccountName=testdata;Accoun‌​tKey=1gy3lpE7Du1j5ljKiupgKzywSw2isjsdfdsfsdfsdsgfsgfdgfdgfd/YThisv/OVVLfIOv9kQ==;"/>
    </connectionStrings>

但有时它会失败并且会通过错误

An unhandled exception of type 'System.FormatException' occurred in Microsoft.WindowsAzure.Storage.dll

Additional information: No valid combination of account information found.

然后请尝试下面的代码:测试和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);