连接到 Azure table 存储失败

connection to Azure table storage fails

我正在开发一个新的网络应用程序,我正在尝试连接到现有的 Azure table 存储。

using System.Web.Mvc;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System;

namespace WebApplication3.Controllers
{
public class GetEmailAddressesController : Controller
{
   public ActionResult Address()
    {
        string emails = "";

        // Parse the connection string and return a reference to the storage account.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("________"));

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        CloudTable table = tableClient.GetTableReference("experimentsEmailAddresses");

        // Construct a table query.
        TableQuery<TableData> query = new TableQuery<TableData>();

        foreach (TableData entity in table.ExecuteQuery(query))
        {
            emails += entity.Email + ";";

        }

        ViewBag.Message = " " + emails;
        return View();
    }

}
} 

代码可以编译,但是当我 运行 它处于调试模式时,我得到一个错误:

System.ArgumentNullException: 'Value cannot be null. Parameter name: connectionString'

即我的连接字符串无效,虽然我从 Azure 中的访问密钥复制了它。

最好的解决方案是什么?

我认为你应该改变:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
        CloudConfigurationManager.GetSetting("________"));

收件人:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
        CloudConfigurationManager.GetSetting("StorageConnectionString"));

希望对您有所帮助!

我改了

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

CloudStorageAccount storageAccount = cloudStorageAccount.Parse("StorageConnectionString");

它似乎工作得很好。