问题描述
我正在从 Table Storage 迁移到 Cosmos DB。 我创建了一个无服务器的 Cosmos DB(Table Azure)
当我执行以下代码时
CloudTable table = _client.GetTableReference(tableName)
await table.CreateAsync();
无服务器不支持读取或替换优惠 帐户。\r\n活动 ID:46c760ee-fb3f-400e-a3fc-819bec68b82b, Microsoft.Azure.Documents.Common/2.14.0、Windows/10.0.19042 documentdb-netcore-sdk/2.11.2"}
为了进行测试,我创建了另一个 Azure CosmosDB,这次使用“预配置吞吐量”而不是“Serveless”,并且可以正常工作。
有什么想法吗?
解决方法
使用 .NET Tables SDK 创建无服务器表仅适用于 REST 模式
你可以试试下面的代码,
TableClientConfiguration config = new TableClientConfiguration();
config.UseRestExecutorForCosmosEndpoint = true;
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(config);
Console.WriteLine("Create a Table for the demo");
// Create a table client for interacting with the table service
CloudTable table = tableClient.GetTableReference(tableName);
if (table.CreateIfNotExists())
{
Console.WriteLine("Created Table named: {0}",tableName);
}
else
{
Console.WriteLine("Table {0} already exists",tableName);
}