[英]connection to Azure table storage fails
I am working on a new web app and I am trying to connect to an existing 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();
}
}
}
The code will compile but when I run it on debug mode I get an error:代码将编译,但当我在调试模式下运行它时,我收到一个错误:
System.ArgumentNullException: 'Value cannot be null. System.ArgumentNullException: '值不能为空。 Parameter name: connectionString'参数名称:connectionString'
ie my connection string isn't valid, although I copied it from the Access keys in Azure.即我的连接字符串无效,尽管我是从 Azure 中的访问密钥复制它的。
What is the best solution for that?什么是最好的解决方案?
I changed我变了
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
to到
CloudStorageAccount storageAccount = cloudStorageAccount.Parse("StorageConnectionString");
And it seems to work perfectly.它似乎完美地工作。
I think you should change:我认为你应该改变:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("________"));
To:到:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
Hope it helps!希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.