I have app with attached database app. In dashboard I see there is DATABASE_URL secret in my app. I have code
builder.Services.AddDbContext(options =>
{
string connectionString = builder.Configuration.GetConnectionString(“name of str”);
if (!builder.Environment.IsDevelopment())
connectionString = Environment.GetEnvironmentVariable(“$DATABASE_URL”);
options.UseNpgsql();
});
But when I deploy app, and use database, I see in logs
An error occurred using the connection to database ‘’ on server ‘’
What’s wrong ?
builder.Services.AddDbContext(options =>
{
string connectionString = builder.Configuration.GetConnectionString(“GiftboxDatabase”);
if (!builder.Environment.IsDevelopment())
connectionString = Environment.GetEnvironmentVariable(“DATABASE_URL”);
options.UseNpgsql(connectionString);
});
Now it gets database connection, but… now there is error
System.ArgumentException: Couldn’t set postgres://all-connection-string-here (Parameter ‘postgres://all-connection-string-here’)
The problem was solved! I must use connection string like this!
Host=host;Port=5432;Username=UserHere;Password=PasswordHere