I am trying to figure out code working for an auto testing as follows:
(in C# code, SQL database used)
- Check whether database (having credentials) is working fine or down?
- If working, run a select query in it & check for succesful execution.
- In any case of failure for above 2 points, automatically send an email to somemone.
Kindly help me out. I think it would be a piece of cake for the experts here.
Thanks a ton
These various steps can be achieved by simply wrapping the database call in some error handling. The overall structure would be something like this:
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
catchstatement).