我有一个从队列触发的函数,并且在函数结束时,它将其发送到Azure表。我现在在本地运行此程序,它已停止在本地工作(指向Azure env),我不知道为什么。在输入函数之前会生成错误,它是:
VehicleCatalog.Storage.AzureTable: Value cannot be null.
Parameter name: <TableName>.
我在local.settings中有一个tableStorage部分
"tableStorage": {
"connectionString": "",
"<tableName>": ""
},
并且我在模拟器中创建了上面提到的表。我也将该设置移至“值”部分,但仍然没有任何乐趣。我不确定是不是该进程失败了。
还有其他我不知道的表来支持此功能,或者是否有人知道我不希望使用模拟器运行此表。
下载Azure存储资源管理器并查找表。
•表名在帐户中必须唯一。
•表名只能包含字母数字字符。
•表名不能以数字字符开头。
•表名不区分大小写。
•表名的长度必须在3到63个字符之间。
•一些表名被保留,包括“表”。尝试创建具有保留表名的表将返回错误代码404(错误请求)。
如果是V2天蓝色功能,则可以尝试使用以下代码和设置:
我的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"
}
}
测试时,它可以正常工作并将实体写入模拟器上的表存储: