Home > database >  .NET 6.0 app on Azure App Service (Linux) can't find connection string
.NET 6.0 app on Azure App Service (Linux) can't find connection string

Time:08-16

Azure first-timer here trying to deploy a .NET 6.0 app to App Service (Linux OS).

In my app, I have a line as follows:

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");

This exception gets thrown on app startup, despite the fact that I'm setting the "DefaultConnection" connection string in the app config in Azure as follows:

conn string

What am I missing?

CodePudding user response:

Looks like the problem was that I'm using Postres, and right now there is a bug/deficiency that prevents .NET from exposing Postgres connection strings to the app.

I didn't think it was even relevant that is a was a Posgres connection string, but here we are.

The fix ended up being to mark the connection string as a "Custom" type in Azure App Service configuration. See here: https://stackoverflow.com/a/62198728/363789

Here is a related Github issue: https://github.com/MicrosoftDocs/azure-docs/issues/95890

  • Related