gpt4 book ai didi

exception - Azure表存储错误: "Unexpected response code for operation : 99"

转载 作者:行者123 更新时间:2023-12-03 17:44:42 25 4
gpt4 key购买 nike

执行以下代码时出现此错误:

var insert = new TableBatchOperation();
foreach (var entity in entities)
{
insert.Insert(entity);
}
cloudTable.ExecuteBatch(insert);

其中实体集合包含 512 个元素。Azure SDK 通过 StorageException:

"Unexpected response code for operation : 99" 

这个错误是什么意思,我该如何解决这个问题?

最佳答案

此非描述性错误意味着 Azure 批量操作(至少在本例中)占用最多 100 个元素。限制你的批处理,你就会好起来的。

我最终使用了这样的东西:

public void Insert(IEnumerable<T> entities)
{
foreach (var chunk in entities.Chunk(100))
{
InsertMaxLimitElements(chunk);
}
}

private void InsertMaxLimitElements(IEnumerable<T> chunk)
{
var insert = new TableBatchOperation();

foreach (var entity in chunk)
{
insert.Insert(entity);
}
cloudTable.ExecuteBatch(insert);
}

Chunk扩展方法是从这个answer复制的:

public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunksize)
{
while (source.Any())
{
yield return source.Take(chunksize);
source = source.Skip(chunksize);
}
}

关于exception - Azure表存储错误: "Unexpected response code for operation : 99",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18170920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com