How to Check Database Integrity with App Insights on ASP.Net Website

In this year’s //oneweek Hackathon at Microsoft, I built a quick ASP.Net front end for our project.  During the hackathon we need to be innovative AND fast!  In our case we had several web jobs (background tasks) for grooming information and inserting new data in the database.  We needed a FAST way to get alerts if any of those background tasks weren’t working correctly without adding additional infrastructure to the solution.  Here are some options we considered:

We settled on something completely different – we wanted to leverage App Insights rich reporting and email capabilities, didn’t want to add additional infrastructure at this time during the Hackathon and needed something done FAST.  Here’s what we ended up doing:

  1. Create a new Controller (DataChecker) with a single action (check data) and an empty View
  2. In the controller action, we implemented any custom logic we wanted for checking the validity of the data (last execution time, last time records were changed, etc) and threw an exception if something wasn’t correct
  3. In the Azure Portal, in the App Insights blade, we implemented a URL Ping test pointed at the action we created above.

The good news is that we get emails quickly if there are any issues with our data PLUS we have a place (right inside our website) to add more unit tests or custom logic for verifying things in the database.  You can use this strategy of having a simple ASP.Net Controller Action to do ‘stuff’ and then wire it to App Insights for a lot things.

Leave a comment below if you found this useful or want a more complete walkthrough!

Comments (0)

Skip to main content