记忆留樱 2015-10-15 10:15 采纳率: 69.2%
浏览 2521
已采纳

从azure storage上取出的数据如果数据记录为0时进行ToList()时出错。

从azure storage上取出的数据如果数据记录为0时进行ToList()时出错。
public IEnumerable RetrieveTableEntitiesInCondition(string tableName, string conditions) where TEntity : ITableEntity, new()
{
IEnumerable entities = null;
try
{
CloudTable table = tableClient.GetTableReference(tableName);
TableQuery query = new TableQuery().Where(conditions);
entities = table.ExecuteQuery(query);
}
catch (Exception ex)
{
logger.Warn("Retrieve condition entity failed: {0}.", ex.ToString());
}
return entities;
}
当该数据记录为0时对该结果进行ToList()操作时抛出异常,异常为:The remote server returned an error: (404) Not Found. Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
求大神帮忙解答为什么ToList()操作会抛出这么个异常。

  • 写回答

1条回答

  • JamborYao_MSFT 2015-10-16 02:58
    关注

    Hi,

    据我测试在特定的condition下返回数据为0时我们依然可以使用ToList(),并不会报错,下面是我尝试的代码,稍有改动。

      public IEnumerable<TEntity> RetrieveTableEntitiesInCondition<TEntity>(string tableName, string conditions ) where TEntity : TableEntity, new()
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(this._stroageConnectionCN);
                var tableClient = storageAccount.CreateCloudTableClient();
                IEnumerable<TEntity> entities = null;
                try
                {
                    CloudTable table = tableClient.GetTableReference(tableName);
                    TableQuery<TEntity> query = new TableQuery<TEntity>().Where(conditions);
                    entities = table.ExecuteQuery(query);                
                }
                catch (Exception ex)
                {
                   // logger.Warn("Retrieve condition entity failed: {0}.", ex.ToString());
                }
    
                return entities;
            }
    

    图片说明
    上面图片也可以看出在没有结果的情况下list得到了一个Count为0的集合,从你的错误的详细情况(remote server returned an error: (404) Not Found. )来看,这个问题的原因可能是由于一些其他问题造成的,我建议你首先检查下你的网络环境,然后再次核对下storage connection是否被串改。

    Best Regards,
    Jambor
    如果您想进一步了解Windows Azure, Windows Azure 官网欢迎您的访问

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作