Base solution for your next web application
Open Closed

Health check Database Connection with status Unhealthy completed - could not connect to database #12272


User avatar
0
mmukkara created

App Version: 13.4 (Angular)

We keep getting this below error in the log and and "could-not-connect-server" page shows up all the time. If I refresh to http://localhost:4200/...When I click on try again, it works. This is happening in development mode and also in production mode.

2024-12-01 13:34:08.172 -05:00 [INF] Request starting HTTP/1.1 GET https://localhost:44301/health - - - -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:08.179 -05:00 [INF] Received HTTP response headers after 10.729ms - 200 -- [System.Net.Http.HttpClient.health-checks.ClientHandler] 2024-12-01 13:34:08.179 -05:00 [INF] Request finished HTTP/1.1 GET https://localhost:44301/health - 200 - application/json 9.3078ms -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:08.179 -05:00 [INF] End processing HTTP request after 10.9461ms - 200 -- [System.Net.Http.HttpClient.health-checks.LogicalHandler] 2024-12-01 13:34:08.179 -05:00 [INF] Saved 4 entities to in-memory store. -- [Microsoft.EntityFrameworkCore.Update] 2024-12-01 13:34:12.868 -05:00 [INF] Request starting HTTP/2 OPTIONS https://localhost:44301/health?d=1733078052860 - - - -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:12.868 -05:00 [INF] CORS policy execution successful. -- [Microsoft.AspNetCore.Cors.Infrastructure.CorsService] 2024-12-01 13:34:12.869 -05:00 [INF] Request finished HTTP/2 OPTIONS https://localhost:44301/health?d=1733078052860 - 204 - - 0.8441ms -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:12.870 -05:00 [INF] Request starting HTTP/2 GET https://localhost:44301/health?d=1733078052860 - application/json - -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:12.871 -05:00 [INF] CORS policy execution successful. -- [Microsoft.AspNetCore.Cors.Infrastructure.CorsService]

2024-12-01 13:34:12.925 -05:00 [ERR] Health check Database Connection with status Unhealthy completed after 49.937ms with message 'JasperDbContext could not connect to database' -- [Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService]

2024-12-01 13:34:12.926 -05:00 [INF] Request finished HTTP/2 GET https://localhost:44301/health?d=1733078052860 - 503 - application/json 55.8047ms -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:18.184 -05:00 [INF] Start processing HTTP request GET https://localhost:44301/health -- [System.Net.Http.HttpClient.health-checks.LogicalHandler] 2024-12-01 13:34:18.184 -05:00 [INF] Sending HTTP request GET https://localhost:44301/health -- [System.Net.Http.HttpClient.health-checks.ClientHandler] 2024-12-01 13:34:18.187 -05:00 [INF] Request starting HTTP/1.1 GET https://localhost:44301/health - - - -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:18.196 -05:00 [INF] Request finished HTTP/1.1 GET https://localhost:44301/health - 200 - application/json 9.2629ms -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:18.196 -05:00 [INF] Received HTTP response headers after 12.0347ms - 200 -- [System.Net.Http.HttpClient.health-checks.ClientHandler] 2024-12-01 13:34:18.196 -05:00 [INF] End processing HTTP request after 12.3581ms - 200 -- [System.Net.Http.HttpClient.health-checks.LogicalHandler] 2024-12-01 13:34:18.197 -05:00 [INF] Saved 4 entities to in-memory store. -- [Microsoft.EntityFrameworkCore.Update] 2024-12-01 13:34:28.199 -05:00 [INF] Start processing HTTP request GET https://localhost:44301/health -- [System.Net.Http.HttpClient.health-checks.LogicalHandler] 2024-12-01 13:34:28.199 -05:00 [INF] Sending HTTP request GET https://localhost:44301/health -- [System.Net.Http.HttpClient.health-checks.ClientHandler] 2024-12-01 13:34:28.203 -05:00 [INF] Request starting HTTP/1.1 GET https://localhost:44301/health - - - -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:28.211 -05:00 [INF] Received HTTP response headers after 11.7903ms - 200 -- [System.Net.Http.HttpClient.health-checks.ClientHandler] 2024-12-01 13:34:28.211 -05:00 [INF] Request finished HTTP/1.1 GET https://localhost:44301/health - 200 - application/json 8.2156ms -- [Microsoft.AspNetCore.Hosting.Diagnostics] 2024-12-01 13:34:28.211 -05:00 [INF] End processing HTTP request after 12.1065ms - 200 -- [System.Net.Http.HttpClient.health-checks.LogicalHandler] 2024-12-01 13:34:28.211 -05:00 [INF] Saved 4 entities to in-memory store. -- [Microsoft.EntityFrameworkCore.Update]

Even if we set false in the appsettings.json for health check..its still an issue "HealthChecks": { "HealthChecksEnabled": true, "HealthChecksUI": { "HealthChecksUIEnabled": true, "HealthChecks": [ { "Name": "InsureIT.Jasper.Web.Host", "Uri": "https://localhost:44301/health" } ], "EvaluationTimeInSeconds": 10, "MinimumSecondsBetweenFailureNotifications": 60 } },

it fails at
using (var uow = _unitOfWorkManager.Begin())

How do we fix this. Its impacting user experience.

Please note, we are not using redis and its not installed.


7 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi mmukkara

    Can you check the database connection? When I tried to repeat this situation, no problem occurred. If there is no problem with the database connection, can you give us more details?

  • User Avatar
    0
    mmukkara created

    Hi @oguzhanagir,

    Database connection is fine (see below). No issue. Everything works fine, just randomly we get the above issue. and when we click on "Try again" or click on back button, it works normally and randomly pops up. This issue is happening in IIS and in development mode.

    "ConnectionStrings": { "Default": "Server=localhost; Database=JasperDb; Trusted_Connection=True; TrustServerCertificate=True; Encrypt=False;" },

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @mmukkara,

    Could you take a look at this PR? https://github.com/aspnetzero/aspnet-zero-core/pull/5422

    If this does not solve your problem, please share your project with [email protected] by deleting node_modules, bin, obj folders

  • User Avatar
    0
    mmukkara created

    Will try with PR. Too big of the project to share in [email protected]. The issue is its very random. It may take 1 min to produce or 2 hours to re-appear.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mmukkara

    Did you have a chance to try this ?

  • User Avatar
    0
    mmukkara created

    we tried to implement the solution and angular application hangs..doesn't allow to go further. We are still getting this issue

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @mmukkara,

    Could you share your AppPreBoostsrap file? Also, can you go to the /health URL?