0
votes

I've a simple Azure function that writes periodically some data into an Azure Table Storage.

var storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("mystorage","xxxxx"),true);

var tableClient = storageAccount.CreateCloudTableClient();

myTable = tableClient.GetTableReference("myData");

TableOperation insertOperation = TableOperation.Insert(data);

myTable.ExecuteAsync(insertOperation);

The code runs well locally in Visual Studio and all data is written correctly into the Azure located Table Storage. But if I deploy this code 1:1 into Azure as an Azure function, the code also runs well without any exception and logging shows, it runs through every line of code.

But no data is written in the Table Storage - same name, same credentials, same code.

Is Azure blocking this connection (AzureFunc in Azure > Azure Table Storage) in some way in contrast to "Local AzureFunc > Azure Table Storage)?

2
Why aren’t you awaiting the ExecuteAsync method call?Gaurav Mantri
btw, if you use this code in an Azure Function, please use Bindings instead of creating the storage account connection yourself docs.microsoft.com/en-us/azure/azure-functions/…silent

2 Answers

2
votes

Is Azure blocking this connection (AzureFunc in Azure > Azure Table Storage) in some way in contrast to "Local AzureFunc > Azure Table Storage)?

No, it's not azure which is blocking the connection or anything of that sort.

You have to await the table operation you are doing with ExecuteAsync as the control in program is moving without that method being completed. Change your last line of code to

await myTable.ExecuteAsync(insertOperation);

Take a look how here on Because this call is not awaited, the current method continues to run before the call is completed.

1
votes

The problem was the rowkey:

I used DateTime.Now for the rowkey (since autoincrement values are not provided by table storage). And my local format was "1.1.2019 18:19:20" while the server's format was "1/1/2019 ..."

And "/" seems not to be allowed in the rowkey string.

Now, formatting the DateTime string correct everything works fine.