【问题标题】:Azure Storage Table Error when running Azure Function运行 Azure Function 时出现 Azure 存储表错误
【发布时间】:2019-10-23 14:24:23
【问题描述】:

我有一个从队列触发的函数,并在函数结束时将其发送到 Azure 表。我现在在本地运行它,它已经停止在本地工作(指向 Azure env),我不知道为什么。进入函数前产生的错误是:

VehicleCatalog.Storage.AzureTable: Value cannot be null.
Parameter name: <TableName>.

我在 local.settings 中有一个 tableStorage 部分

"tableStorage": {
    "connectionString": "",
    "<tableName>": ""
  },

我在模拟器中创建了那里提到的表。我也将该设置移至“值”部分,但仍然没有乐趣。我不确定是不是该进程正在倒下的那张桌子。

是否需要任何其他表来支持这一点,我不知道或有人知道我不知道的东西,以便使用模拟器运行。

【问题讨论】:

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


    【解决方案1】:

    下载 Azure 存储资源管理器并查找表。

    https://docs.microsoft.com/en-us/azure/vs-azure-tools-storage-manage-with-storage-explorer?tabs=windows

    •帐户中的表名必须是唯一的。

    •表名只能包含字母数字字符。

    •表名不能以数字字符开头。

    •表名不区分大小写。

    •表名长度必须为 3 到 63 个字符。

    •某些表名是保留的,包括“tables”。 尝试使用保留表名创建表返回错误代码 404(错误请求)。

    【讨论】:

    • 是的,我拥有所有这些,如果我插入 Azure,它就可以工作。当我使用模拟器时,当我尝试在模拟器中使用表时,我对 QueueTriggers 没有任何问题。
    【解决方案2】:

    如果是 V2 azure 功能,您可以尝试使用以下代码和设置:

    我的function.cs的代码:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Host;
    using Microsoft.Extensions.Logging;
    using Microsoft.WindowsAzure.Storage.Table;
    
    namespace FunctionApp18
    {
        public static class Function1
        {
            [FunctionName("Function1")]
            public static void Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")]string myQueueItem, 
                [Table("test1")]ICollector<Test> outTable,
                ILogger log)
            {
                log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
                outTable.Add(new Test() {
                    PartitionKey = "mypartition_key",
                    RowKey = Guid.NewGuid().ToString(),
                    QuoteText = myQueueItem
                });
            }
        }
    
        //define the table entity
        public class Test : TableEntity
        {
            public string QuoteText { get; set; }
        }   
    
    }
    

    这里是local.settings.json:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "FUNCTIONS_WORKER_RUNTIME": "dotnet"
        }
    }
    

    在测试时,它可以正常工作并将实体写入模拟器上的表存储:

    【讨论】:

    • 事实证明,配置设置已被删除,所以谢谢大家,但我已经通过替换 local.settings 中的值来修复它。
    • @onesixtyfourth,很高兴它已解决。如果我的回答有帮助,请您帮忙标记一下吗?谢谢:)。
    猜你喜欢
    • 2021-10-14
    • 2023-03-11
    • 2015-12-04
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多