gpt4 book ai didi

c# - 部署到 Azure 后 API 连接字符串不起作用

转载 作者:行者123 更新时间:2023-12-03 03:49:03 26 4
gpt4 key购买 nike

首先,我很清楚这可能是重复的。我已经看过但还没有找到解决方案。如果您能给我指出一个,我会很乐意接受!

我使用 Core 5.0 在 VS 2019 中构建了一个 API。这是整个 appsettings.json 文件:

{
"AppSettings": {
"ConnectionStrings": {
"DefaultConnection": "Server=...."
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

在本地主机中完美运行。但是当我发布到 Azure 时,所有结果都会返回:

The ConnectionString property has not been initialized

我读过的一些文章说应用服务将使用应用程序附带的 appsettings.json 文件。其他人说您需要在 Azure 门户中手动添加它们。我尝试以多种方式手动添加连接字符串:

enter image description here

但我仍然得到相同的结果。

我做错了什么?

最佳答案

您需要将 AppSettings 中的 ConnectionStrings 移至更高级别,如下所示,同时确保您在门户中提及相同的内容

"ConnectionStrings": {
"Default": "server=v6.com;database=tsde;uid=sa;pwd=234@123."
},

关于c# - 部署到 Azure 后 API 连接字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67614466/

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