Joel
Joel

Reputation: 438

Azure Table Storage - Create Connection String from a read-only SAS token

I was provided with an Azure table store SAS token with read-only access. I'm able to browse it using Azure Storage Explorer without issues. In trying to access it through a console app, I'm able to parse the connection string with the SAS token as a TableEndpoint but when I try and create the Table Client I get:

System.InvalidOperationException: No credentials provided. at Microsoft.WindowsAzure.Storage.CloudStorageAccount.CreateCloudTableClient()

This syntax I used for the connection string (with replaced values) is:

<add key="StorageConnectionString" value ="TableEndpoint=https://myaccount.table.core.windows.net/Table?sv=2015-04-05&amp;tn=Table&amp;sig=Signature&amp;se=2099-99-99T12%3A00%3A00Z&amp;sp=r" />

Finally, my console app code:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

Upvotes: 4

Views: 3045

Answers (3)

Guus Raaphorst
Guus Raaphorst

Reputation: 56

Stumbled upon this one when having the same issues. The solutions using the StorageCredentials seem to be ok, but I noticed later there is something wrong with the mentioned connection string as well.

In order for the connection string to be valid, it needs to contain 'SharedAccessSignature=', so your connection string should be:

TableEndpoint=https://myaccount.table.core.windows.net;SharedAccessSignature=sv=2015-04-05&amp;tn=Table&amp;sig=Signature&amp;se=2099-99-99T12%3A00%3A00Z&amp;sp=r

I used this for my situation and it works for me.

See also the section on SAS tokens in https://learn.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string

Upvotes: 2

Fei Han
Fei Han

Reputation: 27803

You could refer to the following sample code to use table service endpoint and Shared Access Signature to initialize a new instance of the CloudTableClient class by using new CloudTableClient(Uri, StorageCredentials).

StorageCredentials creds = new StorageCredentials("your SAStoken");

CloudTableClient tableClient = new CloudTableClient(new Uri("your table endpoint"), creds);

Upvotes: 2

Tigran Topchyan
Tigran Topchyan

Reputation: 321

I think you need to use the StorageCredentials class. Here is a sample:

StorageCredentials accountSAS = new StorageCredentials(sasToken);
CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, "account-name", endpointSuffix: null, useHttps: true);
CloudTableClient tableClientWithSAS = accountWithSAS.CreateCloudTableClient();

Upvotes: 8

Related Questions