These various steps can be achieved by simply wrapping the database call in some error handling. The overall structure would be something like this:
try
{
// Perform your SELECT statement
}
catch (SqlException e)
{
// Log the error, send an email, etc.
}
As for what goes where the comments are, that’s up to your setup I guess. The SELECT can be through an ORM, LINQ2SQL, ADO.NET, etc. The error logging would be however you normally log errors, and the sending of the email would be however you normally send emails (hopefully abstracted behind a service call and not manually hitting your SMTP server from within the catch
statement).
solved Automated checking of database connection and query in same database [closed]