Can I create dynamically a table for a serveless Azure CosmosDB (Azure Table)?

176 views Asked by At

i'm making a migration from Table Storage to Cosmos DB. I've created a serveless Cosmos DB (Table Azure)

When i execute the below code

CloudTable table = _client.GetTableReference(tableName)
await table.CreateAsync();

i'm getting an error :

Reading or replacing offers is not supported for serverless accounts.\r\nActivityId: 46c760ee-fb3f-400e-a3fc-819bec68b82b, Microsoft.Azure.Documents.Common/2.14.0, Windows/10.0.19042 documentdb-netcore-sdk/2.11.2"}

To make a test I've created an other Azure CosmosDB with this time "Provisioned throughput" instead of "Serveless" and it works.

Any idea?

1

There are 1 answers

0
Sajeetharan On BEST ANSWER

Serverless table creation with the .NET Tables SDK works in REST mode only

You can try the below code,

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);
}

Here is the reference