Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected response code from CloudTable.ExecuteBatch(..)

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.

like image 556
Dave New Avatar asked Nov 14 '13 11:11

Dave New


1 Answers

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.

like image 121
Dave New Avatar answered Oct 14 '22 01:10

Dave New