When trying to do a batch insert to Azure Table Storage, I am getting a StorageException
on CloudTable.ExecuteBatch()
:
TableBatchOperation batchOperation = new TableBatchOperation();
foreach (var entity in entities)
{
batchOperation.InsertOrReplace(entity);
}
table.ExecuteBatch(batchOperation);
Exception thrown:
Microsoft.WindowsAzure.Storage.StorageException: Unexpected response code for operation : 6 at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase1 cmd, IRetryPolicy policy, OperationContext operationContext) in e:\projects\azure-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\DotNetCommon\Core\Executor\Executor.cs:line 737 at Microsoft.WindowsAzure.Storage.Table.TableBatchOperation.Execute(CloudTableClient client, String tableName, TableRequestOptions requestOptions, OperationContext operationContext) in e:\projects\azure-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\DotNetCommon\Table\TableBatchOperation.cs:line 85 at Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteBatch(TableBatchOperation batch, TableRequestOptions requestOptions, OperationContext operationContext) in e:\projects\azure-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\DotNetCommon\Table\CloudTable.cs:line 165 at Library.Modules.Cloud.TableStorage.StorageTableRepository
1.InsertOrReplaceBatch(List
1 entities)
Inserting these entities normally using TableOperation
gives me no problems.
I cannot find this exception anywhere on the internet or in the MSDN references.
It was due to duplicate RowKey
values. Even with TableBatchOperation.InsertOrReplace(entities)
, the row keys still need to be unique.
Unexpected response code for operation : 6
was referring to the 6th element in the list. The error codes in the Azure SDK are very misleading in my opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With