C
C#2y ago
harry123

❔ Can't deploy my C# ASP.NET MVC + Postgres app to Azure

Hey ! I am trying to deploy an ASP.NET MVC 7 + EF + Postgres app on Azure but my app crashes on start. Weird thing is that it doesn't seems like it can connect to the database, and it loads the empty value stored in my appsettings.json instead of the ConnectionString i added in Azure. If i don't set the empty string the app just crashes saying that my AZURE_POSTGRESQL_CONNECTIONSTRING connection string is not set. However, when i manually ssh into the server and then set my prod database string it does work... Since i am using a CI/CD pipeline, it is kind of boring to set them every new deploy
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
harry123
harry123OP2y ago
Here is how i am resolving the value in my application :
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("AZURE_POSTGRESQL_CONNECTIONSTRING") ?? throw new InvalidOperationException("Connection string 'AZURE_POSTGRESQL_CONNECTIONSTRING' not found.");

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

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddControllersWithViews();
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("AZURE_POSTGRESQL_CONNECTIONSTRING") ?? throw new InvalidOperationException("Connection string 'AZURE_POSTGRESQL_CONNECTIONSTRING' not found.");

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

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddControllersWithViews();
And i am setting the value into the settings of my Azure Web App!
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
harry123
harry123OP2y ago
Even if i set the Connection strings into the Connection string section ?? Seems weird I'll try I have tried to set the connection string like you said, and it still doesn't work :/ i've been trying to fix this problem since a week and even when looking at microsoft docs i couldn't find a solution Wait, i'll try changing my ConnectionString Ssl Mode since theres been a breaking change into Npgsql ssl library, havent tried that yet Edit : still not working :/ 2nd edit : wait, i havent applied migrations 3rd edit : everything seems to be working again, i don't know how ??
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server