Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure ConnectionStrings feature not working with ASP.NET app

I am totally new to using Azure services. I've been trying to deploy a C# / ASP.NET Core 7 app I created that relies on Postgres as the database and Entity Framework as ORM.

I used App Services (Linux) to deploy my app from a GitHub Action and the Postgres flexible server as the database.

However my app is unable to load the Connection string I added into the "Settings > Configuration > Connection strings".

Here is the code I use to load it in my Program.cs file:

// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");

builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseNpgsql(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();

The app works successfully when used locally w/ docker.

I tried to use Microsoft Key Store but it failed. Also tried to load connection string from env instead of configuration file. Last thing I have done is put into my appsettings.json a section ConnectionStrings with a DefaultConnection and an empty string to it, and that didn't work

like image 353
kittyyy Avatar asked Oct 16 '25 02:10

kittyyy


1 Answers

If you are deploying to Azure App Service there are basically two options to ship application settings:

  1. make sure that your local appsetting.json is also copied to output directory (check file properties)

  2. you can setup application settings including Connection Strings in App Settings tab of you App Service instance

like image 116
Adel Nazirov Avatar answered Oct 17 '25 16:10

Adel Nazirov