gpt4 book ai didi

azure - 由于未设置连接字符串,无法运行 azure 函数并出现错误

转载 作者:行者123 更新时间:2023-12-03 05:01:19 24 4
gpt4 key购买 nike

我有这个azure函数,它应该从服务总线队列读取消息。

我已经在代码中给出了连接字符串,但在运行 func 时仍然抛出错误 -

Set the connection string named 'Endpoint=sb://demoser
vicebus2019.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKe
y;[Hidden Credential]' in the connectionStrings section of the .config file in t
he following format <add name="Endpoint=sb://demoservicebus2019.servicebus.windo
ws.net/;SharedAccessKeyName=RootManageSharedAccessKey;[Hidden Credential]" conne
ctionString="DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY

代码-函数1.cs

 public static class Function1
{
[FunctionName("Function1")]
public static void Run([QueueTrigger("customer", Connection = "Endpoint=sb://demoservicebus2019.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=text")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
}

本地.setting.json

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "storageaccount-connectionstring",
"AzureWebJobsDashboard": "storageaccount-connectionstring"
}
}

最佳答案

因此连接属性是环境/配置变量的键,而不是实际的连接字符串。

您可以阅读有关绑定(bind)的信息 here

The name of an app setting that contains the Storage connection string to use for this binding

所以将其更改为:

public static class Function1
{
[FunctionName("Function1")]
public static void Run([QueueTrigger("customer", Connection = "MyConnection")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
}

配置

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "storageaccount-connectionstring",
"AzureWebJobsDashboard": "storageaccount-connectionstring"
"MyConnection":"Endpoint=sb://demoservicebus2019.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=text"
}
}

关于azure - 由于未设置连接字符串,无法运行 azure 函数并出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56786532/

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