c# - 来自 CloudTable.ExecuteBatch(..) 的意外响应代码

标签 c# azure azure-storage azure-table-storage

尝试批量插入 Azure 表存储时,我在 CloudTable.ExecuteBatch() 上收到 StorageException:

TableBatchOperation batchOperation = new TableBatchOperation();

foreach (var entity in entities)
{
    batchOperation.InsertOrReplace(entity);
}

table.ExecuteBatch(batchOperation);

抛出异常:

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)

通常使用 TableOperation 插入这些实体不会给我带来任何问题。

我在 Internet 或 MSDN 引用文献中找不到此异常。

最佳答案

这是由于重复的 RowKey 值造成的。即使使用 TableBatchOperation.InsertOrReplace(entities),行键仍然需要是唯一的。

操作的意外响应代码:6 引用了列表中的第 6 个元素。在我看来,Azure SDK 中的错误代码非常具有误导性。

关于c# - 来自 CloudTable.ExecuteBatch(..) 的意外响应代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19976862/

相关文章:

C#设置上传文件内容类型

c# - 更新包装对象的最佳方法

azure - Azure ARM 嵌套模板能否以“完整”模式部署?

c# - Azure CloudBlobContainer.CreateIfNotExists 返回 403 forbidden

c# - 存储客户端库 2.0 - 为什么 API 使用起来不如 1.7 那么直观?

azure - 如何使用Azure上/dev/sdb1下的空磁盘空间?

c# - CollectionAssert.Contains() 作为 NUnit 的 Assert.Contains() 的替代品

c# - 从 iframe 中读取查询字符串参数

azure - 确保授权 header 的值格式正确,包括签名

azure - 在没有 Teams-Context 的情况下可以与 Microsoft Teams 的 Bot Framework 发起主动对话吗?