【发布时间】:2018-11-11 15:53:28
【问题描述】:
我正在开发一个新的 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: '值不能为空。参数名称: 连接字符串'
即我的连接字符串无效,尽管我从 Azure 中的访问密钥复制了它。
什么是最好的解决方案?
【问题讨论】:
-
您将连接字符串存储在配置文件中的什么位置?
-
在 web.config 下我添加了
-
具体是在appSettings还是connectionStrings下?
-
它在appSettings下
-
我的另一个建议是: 1. 逐步检查并确保 CloudConfigurationManager.GetSetting("________"));正在返回您认为的内容。 2. 获取应用返回的连接字符串并尝试通过 Azure 存储资源管理器进行连接。
标签: .net azure web-applications azure-table-storage