Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using AspNetCore.Health;
- using System.Data.SqlClient;
- using System.Data;
- namespace BorrowWorks.Nortridge.LoanSystem.WebApi.Health
- {
- public static class HealthCheckContextExtensions
- {
- public static HealthCheckContext AddConnectionStringCheck(
- this HealthCheckContext checkContext,
- string name,
- string connectionString)
- {
- checkContext.Add(name, async () =>
- {
- try
- {
- SqlConnection connection = new SqlConnection(connectionString);
- await connection.OpenAsync();
- if ((connection.State & ConnectionState.Open) > 0)
- {
- connection.Close();
- return HealthCheckResult.Healthy(name);
- }
- else
- {
- return HealthCheckResult.Unhealthy(name);
- }
- }
- catch
- {
- return HealthCheckResult.Unhealthy(name);
- }
- });
- return checkContext;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement