Skip to content

Latest commit

 

History

History
66 lines (52 loc) · 1.83 KB

SqlServer.md

File metadata and controls

66 lines (52 loc) · 1.83 KB

LiteX HealthChecks SqlServer

SqlServer health checks package used to check the status of a SqlServer in ASP.NET Core applications.

LiteXHealthChecks is very small yet powerful and high-performance library used to check the status of a component in the application, such as a backend service, database or some internal state.

Basic Usage

Install the package

Install via Nuget.

PM> Install-Package LiteX.HealthChecks.SqlServer
AppSettings
{  
  "Data": {
    "ConnectionStrings": {
      "SqlServer": "Server=.;Initial Catalog=master1;Integrated Security=true"
    }
  }
}
Configure Startup Class
public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        // 1: Use default configuration
        services.AddHealthChecks()
            .AddSqlServer(Configuration["Data:ConnectionStrings:SqlServer"]);

        // OR
        // 2: With all optional configuration
        services.AddHealthChecks()
            .AddSqlServer(
                connectionString: Configuration["Data:ConnectionStrings:SqlServer"],
                sqlQuery: "SELECT 1;",
                name: "sql-server",
                failureStatus: HealthStatus.Unhealthy,
                tags: new string[] { "db", "sql", "sqlserver" });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseHealthChecks("/health");
    }
}

Sample Usage Example

Sample for other services.

For more helpful information about LiteX HealthChecks, Please click here.