与Azure表存储的连接失败

时间:2018-11-11 15:53:28

标签: .net azure web-applications azure-table-storage

我正在使用新的Web应用程序,并且试图连接到现有的Azure表存储。

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:'值不能为null。参数名称:connectionString'

尽管我从Azure的Access键复制了连接字符串,但我的连接字符串无效。

什么是最佳解决方案?

2 个答案:

答案 0 :(得分:0)

我认为您应该更改:

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

收件人:

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

希望有帮助!

答案 1 :(得分:0)

我改变了

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

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

它似乎运行完美。