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
If you are deploying to Azure App Service there are basically two options to ship application settings:
make sure that your local appsetting.json
is also copied to output directory (check file properties)
you can setup application settings including Connection Strings in App Settings tab of you App Service instance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With