Low-Cost High Availability: Simple Database Monitoring in a Windows Environment : Page 5
The .NET Framework 2.0 and Visual Studio 2005 make it easy to create a basic but extensible database-monitoring solution without a lot of complexity or coding.
by John Paul Cook
Sep 20, 2006
Page 5 of 5
WEBINAR:
On-Demand
Application Security Testing: An Integral Part of DevOps
To install a Windows Service project, add a Setup Project to the solution:
In the Solution Explorer, add a new Setup and Deployment project to the solution. Give it a meaningful name such as SetupMonitorService (see Figure 6).
Figure 6. Adding a Setup and Deployment Project to the Solution
In the Solution Explorer, right-click SetupMonitorService and select Add | Project Output (see Figure 7).
Figure 7. Adding Project Output from the Service Project to the Setup Project
On the Add Project Group Output dialog box, confirm that you have Primary output selected and click OK (see Figure 8).
To add a custom action, right-click Custom Actions and select Add Custom Action. The "Select Item in Project" dialog box appears. Double-click the Application Folder (see Figure 10).
Figure 10. Select Item in Project Dialog Box Superimposed Over the Custom Actions Editor
Select Primary output from MonitorService (Active) and click OK (see Figure 11).
Figure 11. Select Primary Output from MonitorService (Active) and Click OK
Build the setup project by right-clicking it in Solution Explorer and selecting Build (see Figure 12). Resolve any errors and save your solution.
Since you specified that the service will execute in the context of a user account, the installer prompts you for the user's credentials (see Figure 14).
Figure 14. Set Service Login Dialog Box Superimposed Over the Installer Window
Although the service is set to start automatically, it does not do so after installation. It will start automatically after a reboot. You could add code to make it start automatically after installation, but to keep things simple, use the Services applet from Administrative Tools to start the service initially (see Figure 15).
Figure 15. Select the Monitor Service and Click Start
You can stop the service and change entries in the MonitorService.exe.config file and restart the service to have it use the new values, such as IntervalMsec. To force a connection failure during testing, change the name of the server in a connection string to an invalid server name.
Power and Ease of Use in .NET 2.0
You have seen some of the .NET Framework 2.0's powerful yet easy-to-use features in action:
When you use its ConfigurationManager class with an application configuration file, you eliminate the need to recompile after changing application parameters and settings, which reduces brittleness.
DbFactory classes further reduce brittleness by making data-access code provider agnostic.
Generic lists simplify code by providing simple-to-use abstractions in code.
The System.Net.Mail namespace greatly simplifies the task of sending mail from an application.
Windows Services allow durable applications to be built.