- Open
SqlHealthCheck.slnin Visual Studio - Update connection string in
SqlCheckDemo/Program.cs(line 13) - Press F5 to run
# Navigate to the solution folder
cd SqlHealthCheck
# Build everything
dotnet build
# Run with default connection (localhost)
cd SqlCheckDemo
dotnet run
# Or run with your own connection string
dotnet run "Server=YOUR_SERVER;Database=master;Integrated Security=true;TrustServerCertificate=true;"=== SQL Server Health Check Demo ===
Loaded 12 checks from sql-checks.json
Testing connection...
β
Connected successfully
Running checks...
[Backup]
------------------------------------------------------------
β
Full Backup Recency
β
Transaction Log Backup Recency
[Configuration]
------------------------------------------------------------
β
Auto Close Enabled
β
Auto Shrink Enabled
β TempDB File Count [Info]
Check failed. Expected: 0, Got: 1. Add more TempDB data files...
β
Percentage Growth Settings
[Integrity]
------------------------------------------------------------
β
Database Corruption Detected
[Performance]
------------------------------------------------------------
β High Index Fragmentation [Warning]
Check failed. Expected: 0, Got: 1. Consider rebuilding...
β
Missing Index Recommendations
β
Excessive VLF Count
[Security]
------------------------------------------------------------
β
SA Account Enabled
β
Weak Password Policies
=== Summary ===
Total Checks: 12
Passed: 10
Failed: 2
The first time you run, it creates sql-checks.json in the SqlCheckDemo folder.
Edit that file to:
- βοΈ Change thresholds (e.g., backup age from 7 to 3 days)
- β Add new checks (see USAGE.md for examples)
- π Disable checks you don't care about
- π Update SQL queries for your environment
No recompile needed - just edit the JSON and run again!
SqlHealthCheck/
βββ SqlCheckLibrary/ # The reusable library
β βββ Models/ # SqlCheck and CheckResult classes
β βββ Services/ # CheckRunner and CheckRepository
βββ SqlCheckDemo/ # Console app demo
β βββ Program.cs # Change connection string here
βββ sql-checks.json # Auto-generated on first run - EDIT THIS!
using SqlCheckLibrary.Services;
var repo = new CheckRepository();
await repo.LoadChecksAsync();
var runner = new CheckRunner("your-connection-string");
var results = await runner.RunChecksAsync(repo.GetEnabledChecks());
// Do whatever you want with results!
foreach (var fail in results.Where(r => !r.Passed))
{
Console.WriteLine($"Issue: {fail.CheckName}");
SendAlert(fail); // Your alert logic
}var servers = new[] { "sql01", "sql02", "sql03" };
foreach (var server in servers)
{
var connStr = $"Server={server};Database=master;Integrated Security=true;TrustServerCertificate=true;";
var runner = new CheckRunner(connStr);
var results = await runner.RunChecksAsync(repo.GetEnabledChecks());
SaveToDatabase(server, results); // Store in monitoring DB
}That's it. Super simple. All checks are in JSON, easy to modify, zero magic.
Go plant those trees! π³