Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between using AddDbContextCheck and AddSqlServer for HealthCheck?

I have this code which can be used to check the database health using C# in NET 6.

Version 1:

var hcBuilder = builder.Services.AddHealthChecks();    
hcBuilder.AddSqlServer(myServicesConnStr);

Version 2:

builder.Services.AddHealthChecks()
    .AddDbContextCheck<MyServicesContext>();

What is the difference between version 1 and version 2 in regards to checking the health of the database using HealthCheck package? Is there any difference in its efficiency?

like image 982
Steve Avatar asked Sep 19 '25 16:09

Steve


1 Answers

Version 1. from AspNetCore.HealthChecks.SqlServer : It is not maintained or supported by Microsoft.

Version 2. from Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore : It is maintained and supported by Microsoft.

like image 82
mkmkmk Avatar answered Sep 22 '25 08:09

mkmkmk