10
votes

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.StorageTableRepository1.InsertOrReplaceBatch(List1 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.

1
Can you check if all entities in the batch 1) are having same PartitionKey and 2) an entity is not repeated more than once in the batch. Based on the error message, look at the 7th entity in your batch. That entity is causing problem.Gaurav Mantri

1 Answers

15
votes

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.