0

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)
3
  • That's not a .NET Error. It looks like a diagnostic entry in a log. What's the actual full exception text ? Are you using migrations? In that case this may be related to this issue Commented Jul 11 at 8:51
  • all migrations are checked immediately when the application is launched. But at the moment they have not been applied Commented Jul 11 at 9:42
  • Check means executed? So this could be due to migrations that are being applied? How are they checked or applied? You need to add the missing information in the question. Right now we don't even have an error message Commented Jul 11 at 9:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.