This repository was archived by the owner on Apr 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
src/NET6CustomLibrary/Docs/HealthChecks Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Health Checks configuration for SQL server database
2
+
3
+
4
+ ## Configuration to add to the appsettings.json file
5
+
6
+ ``` json
7
+ "ConnectionStrings" : {
8
+ "Default" : " Data Source=[SERVER];Initial Catalog=[DATABASE];User ID=[USERNAME];Password=[PASSWORD]"
9
+ //or "Default": "Data Source=[SERVER];Initial Catalog=[DATABASE];User ID=[USERNAME];Password=[PASSWORD];Encrypt=False"
10
+ },
11
+ ```
12
+
13
+
14
+ ## Registering services at Startup
15
+
16
+ ``` csharp
17
+ public Startup (IConfiguration configuration )
18
+ {
19
+ Configuration = configuration ;
20
+ }
21
+
22
+ public IConfiguration Configuration { get ; }
23
+
24
+ public void ConfigureServices (IServiceCollection services )
25
+ {
26
+ var connectionString = Configuration .GetSection (" ConnectionStrings" ).GetValue <string >(" Default" );
27
+ services .AddSqlServerHealthChecks (connectionString , " SQLServer" );
28
+ }
29
+
30
+ // OMISSIS
31
+
32
+ public void Configure (WebApplication app )
33
+ {
34
+ // OMISSIS
35
+
36
+ app .UseEndpoints (endpoints =>
37
+ {
38
+ endpoints .MapControllers ();
39
+ endpoints .AddDatabaseHealthChecks (" /status" , false ); // Use the True parameter if access is to be in AllowAnonymous mode
40
+ }
41
+ }
42
+ ```
You can’t perform that action at this time.
0 commit comments