I created an Azure Function app with two functions inside. I get the connection string using this code (and it works when I run it locally):
var connectionString = Environment.GetEnvironmentVariable("PostgresConnectionString");
Then I did the connection string setup in azure portal, which resulted in this appsettings.json configuration:
But when I trigger the function, this is what I get in the logs:
Result: Failure
Exception: System.AggregateException: One or more errors occurred. (The ConnectionString property has not been initialized.)
---> System.InvalidOperationException: The ConnectionString property has not been initialized.
at Npgsql.ThrowHelper.ThrowInvalidOperationException(String message)
at Npgsql.NpgsqlConnection.Open(Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.OpenAsync(CancellationToken cancellationToken)
Any ideas on how can I make that connection string visible to the code inside Program.cs file?