当尝试批量插入Azure表存储时,我在 CloudTable.ExecuteBatch()
上获得 StorageException
:
TableBatchOperation batchOperation = new TableBatchOperation();
foreach (var entity in entities)
{
batchOperation.InsertOrReplace(entity);
}
table.ExecuteBatch(batchOperation);
Exception thrown:
Microsoft.WindowsAzure.Storage.StorageException:操作的意外响应代码:6位于e:\ projects \ azure中的Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [T](StorageCommandBase1 cmd,IRetryPolicy策略,OperationContext operationContext) -sdk-for-net \ microsoft-azure-api \ Services \ Storage \ Lib \ DotNetCommon \ Core \ Executor \ Executor.cs:Microsoft.WindowsAzure.Storage.Table.TableBatchOperation.Execute的第737行(CloudTableClient客户端,String tableName, TableRequestOptions requestOptions,OperationContext operationContext)在e:\ projects \ azure -sdk-for-net \ microsoft-azure-api \ Services \ Storage \ Lib \ DotNetCommon \ Table \ TableBatchOperation.cs:Microsoft.WindowsAzure.Storage.Table第85行.CloudTable.ExecuteBatch(TableBatchOperation batch,TableRequestOptions requestOptions,OperationContext operationContext)在e:\ projects \ azure-sdk-for-net \ microsoft-azure-api \ Services \ Storage \ Lib \ DotNetCommon \ Table \ CloudTable.cs:第165行在Library.Modules.Cloud.TableStorage.StorageTa bleRepository1.InsertOrReplaceBatch(List1实体)
通常使用 TableOperation
插入这些实体不会给我带来任何问题 .
我无法在互联网或MSDN参考中的任何地方找到此异常 .
1 回答
这是由于重复
RowKey
值 . 即使使用TableBatchOperation.InsertOrReplace(entities)
,行键仍然必须是唯一的 .Unexpected response code for operation : 6
指的是列表中的第6个元素 . 在我看来,Azure SDK中的错误代码非常具有误导性 .