gpt4 book ai didi

c# - 如何连接到 Azure Table/Cosmos 存储模拟器

转载 作者:行者123 更新时间:2023-12-01 11:19:50 24 4
gpt4 key购买 nike

这里的文档( https://learn.microsoft.com/en-us/azure/storage/storage-use-emulator )说端点应该是这种格式来访问模拟表存储:

http://127.0.0.1:10002/<account-name>/<resource-path>

但是,我在哪里可以获得 <account-name><resource-path>来自模拟器内的项目?

有人知道连接模拟器的工作演示吗?我似乎找到的唯一一个是用于连接到 Azure 的。

最佳答案

如果我们要连接到存储模拟器,代码演示与Azure存储相同。不同之处在于存储模拟器使用众所周知的帐户名和 key 。

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;

To target the storage emulator, you can use a shortcut that maps to the well-known account name and key.

在这种情况下,您的连接字符串设置是:

<add key="StorageConnectionString" value="UseDevelopmentStorage=true;" />

我们可以从Azure的官方文档中获取代码演示。

// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));

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

// Retrieve a reference to the table.
CloudTable table = tableClient.GetTableReference("people");

// Create the table if it doesn't exist.
table.CreateIfNotExists();

关于如何使用Cosmos模拟器,可以从Use the Azure Cosmos DB Emulator for local development and testing得到答案.

我们需要安装Cosmos emulator本地。

his account and key are the only credentials permitted for use with the Azure Cosmos DB Emulator. They are:

Account name: localhost:<port>
Account key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==

演示代码:

// Connect to the Azure Cosmos DB Emulator running locally
DocumentClient client = new DocumentClient(
new Uri("https://localhost:8081"),
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

关于c# - 如何连接到 Azure Table/Cosmos 存储模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45244590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com