My mobile app sends the current location to my .NET Core app very often and a lot.
My .NET Core application using Entity Framework Core with a PostgreSQL database hosted on Azure (Flexible Server).
After deploying or restarting the app, I sometimes get the following error on the first requests:
An error occurred using the connection to database '' on server ''.
RequestPath: /api/v2/couriers/guid/locations
EventId.Name: Microsoft.EntityFrameworkCore.Database.Connection.ConnectionError
Database configuration:
public static WebApplicationBuilder ConfigureDatabase(this WebApplicationBuilder builder)
{
var connectionString = builder.Configuration.GetConnectionString("Database")
?? throw new InvalidOperationException("Connection string 'Database' not found.");
builder.Services.AddDbContextFactory<ApplicationDbContext>(options =>
options.UseNpgsql(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure()));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
return builder;
}
After a short time (10-30 seconds), the error disappears and everything works fine.
What I've checked:
- The connection string is correct.
- The database is up and running.
- The error only occurs right after the app starts (cold start)