简体   繁体   中英

API Connection String Not Working After Deploying to Azure

First, I am well aware this may be a duplicate. I have looked but have not yet found a solution. If you can point me to one, I will gladly accept it!

I've built an API in VS 2019 using Core 5.0. This is the entire appsettings.json file:

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

Works perfectly in localhost. But when I publish to Azure, all the results come back:

The ConnectionString property has not been initialized

SOME articles I have read say that the App Service will use the appsettings.json file that comes with the app. Others say you need to add them manually in Azure Portal. I have tried adding the connection string manually, in multiple ways:

在此处输入图像描述

But I still get the same result.

What am I doing wrong?

You need to take the ConnectionStrings out of AppSettings to a higher level as below, also make sure you are mentioning the same in the portal

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

I found something which may be useful on https://docs.microsoft.com : Configure apps

For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in in Web.config or appsettings.json, but the values in App Service override the ones in Web.config or appsettings.json. You can keep development settings (for example, local MySQL password) in Web.config or appsettings.json and production secrets (for example, Azure MySQL database password) safely in App Service. The same code uses your development settings when you debug locally, and it uses your production secrets when deployed to Azure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM