gpt4 book ai didi

azure - 部署Azure Function时ConnectionString为null

转载 作者:行者123 更新时间:2023-12-02 23:38:58 24 4
gpt4 key购买 nike

我一直在使用 Azure 的函数,我按照链接 here 的示例在本地构建了一个非常简单的 Http Function ,唯一的区别是我定义了一个 User 表而不是 Todo 表

本地一切都按预期运行,我可以发布和获取。

但是,在部署该函数并尝试发出 POST 请求时,我在日志中看到以下内容:

Executed 'User' (Failed, Id=5df9dffe-eedf-4b11-aa10-54fda00992b0, Duration=1ms)System.ArgumentNullException : Value cannot be null. (Parameter 'connectionString')

我已经检查了 SQL Server,以确保其他 Azure 服务可以访问它,只是将导致问题的部分封装起来,但我可以确认它已设置为允许。

我找到了this question ,我已完成这些步骤并检查了我的步骤,我可以确认我的 Function App 配置确实具有 AzureWebJobsStorage 连接字符串。

由于我目前缺乏功能知识,我不能 100% 确定为什么会发生这种情况,还有其他人经历过这种情况吗?如果是的话你是如何解决的?

更新

经过进一步测试,错误似乎来 self 的 Startup 类,

class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
string connectionString = Environment.GetEnvironmentVariable("SqlConnectionString");
builder.Services.AddDbContext<ApplicationDbContext>(
options => SqlServerDbContextOptionsExtensions.UseSqlServer(options, connectionString));
}
}

部署后,connectionString 变量为 null...但不确定原因。

最佳答案

是的,您无法获取它,因为您没有在配置设置中设置它。

enter image description here

关于azure - 部署Azure Function时ConnectionString为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65649441/

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