简体   繁体   English

C# Azure - 从 Microsoft.Azure.Cosmos.Table 移动到 Azure.Data.Tables 后找不到指定的资源

[英]C# Azure - Specified Resource not found after moving from Microsoft.Azure.Cosmos.Table to Azure.Data.Tables

I have an Azure storage account with a table that we are trying to access using C# in a function app.我有一个 Azure 存储帐户,其中有一个表,我们正尝试在 function 应用程序中使用 C# 访问该表。 I migrated over from the deprecated Microsoft.Azure.Cosmos.Table library to Azure.Data.Tables.我从已弃用的 Microsoft.Azure.Cosmos.Table 库迁移到 Azure.Data.Tables。

I get an error when trying to query the table for an entity.尝试在表中查询实体时出现错误。

{
"The specified resource does not exist.
RequestId:8612b003-0002-0071-64b2-054424000000
Time:2022-12-01T18:27:02.5504487ZrnStatus: 404 (Not Found)
ErrorCode: ResourceNotFound
Content:
{
    "odata.error":
    {
    "code":"ResourceNotFound",
        "message":
        {
            "lang":"en-US",
            "value":"The specified resource does not exist.
            RequestId:8612b003-0002-0071-64b2-054424000000
            Time:2022-12-01T18:27:02.5504487Z"
        }
    }
}
rnrnHeaders:rnCache-Control: no-cacher
Transfer-Encoding: chunked
Server: Windows-Azure-Table/1.0,
Microsoft-HTTPAPI/2.0
x-ms-request-id: 8612b003-0002-0071-64b2-054424000000
x-ms-client-request-id: c1668171-b91f-4eba-b2d1-1fef1120595a
x-ms-version: REDACTED
X-Content-Type-Options: REDACTED
Date: Thu, 01 Dec 2022 18:27:02 GMT
Content-Type: application/json; 
odata=minimalmetadata; 
streaming=true; 
charset=utf-8rn"
}

Old previous working code旧的以前的工作代码

var primaryCloudStorageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("EntityRegistryStorageAccountConnectionString"));
var tableClient = primaryCloudStorageAccount.CreateCloudTableClient();
_registry = tableClient.GetTableReference("EntityRegistry");

Code with new libary that is not working使用无法正常工作的新库的代码

private readonly TableClient _registry;
_registry = new TableClient(Environment.GetEnvironmentVariable("EntityRegistryStorageAccountConnectionString"), "EntityRegistry");

Also tried this也试过这个

var tableClient = new TableServiceClient(Environment.GetEnvironmentVariable("EntityRegistryStorageAccountConnectionString"));
_registry = tableClient.GetTableClient("EntityRegistry");

Error is thrown in this code此代码中抛出错误

var registryRecord = await _registry.GetEntityAsync<TableEntity>(entityType.ToString(), registryId);

This also returns a 404 error这也会返回 404 错误

var registryRecord = await _registry.GetEntityIfExistsAsync<TableEntity>(entityType.ToString(), registryId);

I know the table exists and it seems to be authenticating me, I can see the URL that is being set on the TableClient and it matched what I see in Azure. I also use the connection string from Azure that has the account and key.我知道该表存在并且它似乎正在对我进行身份验证,我可以看到在 TableClient 上设置的 URL,它与我在 Azure 中看到的相匹配。我还使用来自 Azure 的连接字符串,其中包含帐户和密钥。

What could be going on with this?这可能是怎么回事?

Important note!重要的提示!

In the past library, the GetEntity call would be okay with returning null if the record does not exist.在过去的库中,如果记录不存在,GetEntity 调用可以返回 null。 In this case, you need to call GetEntityIFExistsAsync and parse the value returned, it won't just return null like it did previously if the value does not exist.在这种情况下,您需要调用 GetEntityIFExistsAsync 并解析返回的值,如果该值不存在,它不会像以前那样只返回 null。

var registryRecord = await _registry.GetEntityIfExistsAsync<TableEntity>(entityType.ToString(), registryId);

                if (registryRecord.HasValue)
                    return registryRecord.Value;
                else
                    return null;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft.Azure.Cosmos.Tables 到 Azure.Data.Tables 迁移:TableEntity Inheritance - Microsoft.Azure.Cosmos.Tables to Azure.Data.Tables migration: TableEntity Inheritance Microsoft.Azure.Cosmos.Table 和 Microsoft.WindowsAzure.Storage 之间的 ExecuteQuerySegmentedAsync 性能显着下降 - Significant performance degration on ExecuteQuerySegmentedAsync between Microsoft.Azure.Cosmos.Table and Microsoft.WindowsAzure.Storage 在 Microsoft.Azure.Cosmos.Table 中使用 TableEntity.Flatten 的正确方法是什么? - What is the right way to use TableEntity.Flatten in Microsoft.Azure.Cosmos.Table? Azure.Data.Tables C# SDK 查询时间戳返回零结果 - Azure.Data.Tables C# SDK query Timestamp returning zero results Microsoft.Azure.Cosmos.Table LocationMode.SecondaryOnly RA-GRS Exception 此操作只能针对主存储位置执行 - Microsoft.Azure.Cosmos.Table LocationMode.SecondaryOnly RA-GRS Exception This operation can only be executed against the primary storage location 找不到资源 Azure Cosmos DB - Resource Not Found Azure Cosmos DB 如何使用 Azure.Data.Tables 列出表(按前缀)? - How to list tables (by prefix) with Azure.Data.Tables? Azure.Data.Tables 仅查询下一条记录(限制/取 1?) - Azure.Data.Tables querying only next record (limit/take 1?) Azure.Data.Tables 通用基础 class 问题 - Azure.Data.Tables generic base class issue 使用 Azure.Data.Tables 中的 TableClient.Query 限制查询结果 - Limiting query results using TableClient.Query from Azure.Data.Tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM