Search code examples
c#.netazureswagger

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:

enter image description here

But I still get the same result.

What am I doing wrong?


Solution

  • 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."
      },