2010-02-26 116 views

回答

1

您不必为Azure云存储创建连接字符串,通过API访问此服务(与blob和队列相同),MS为此提供了一个soap API和一个REST API。

您应该下载适用于样本和工具的Windows Azure SDK(如果要在本地进行测试,则使用Azure Fabric),那么您可以获得Here

SQL Azure不同,SQL Azure是“云中的SQL Server”,对于该服务,您只需要一个连接字符串,与普通的SQL Server连接字符串非常相似。

+1

当您使用Azure SDK时,确实会创建一个连接字符串。 – 2013-08-20 16:25:46

+0

@JasonDufair 3 1/2年前,当我回答这个问题时,要访问Azure Table Services(而不是SQL Azure),所需的只是端点和密钥。在投票人选之前,你需要看历史背景。 – 2013-08-20 21:20:50

+0

仅供参考,这是我们当时所做的事情... http://convective.wordpress.com/2010/08/18/examples-of-the-windows-azure-storage-services-rest -api/ – 2013-08-20 21:37:31

8

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

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

您按照下面建一个配置字符串: http://msdn.microsoft.com/en-us/library/ee758697.aspx

还有就是在IDE中的助手,如果你右击角色。

1

连接字符串到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. 

,那么请尝试用下面的代码:测试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);