SQL Mode

SqlMode
Often I develop software using SQL Server as the database and I may need it running on the local machine, but when I do not need SQL Server running on the local machine perhaps because I am accessing SQL Server on a Server or I am developing an application that does not need it, I want to be able to enable SQL Server or disable it to save memory and CPU cycles.  Therefore, I wrote a simple utillity to show the status of the various services making up SQL Server and the ability to turn them off or on as shown above.

In the code you will find two lines of code where the services and their status is defined and tese can be changed according to your needs and the version of SQL Server:

// The service names to access
private static string[] serviceNames = new string[] { "SQLBrowser", "MSSQLFDLauncher$SQLEXPRESS", "ReportServer$SQLEXPRESS", "SQLWriter", "SQLAgent$SQLEXPRESS", "MSSQL$SQLEXPRESS" };
// The service modes, if "Disabled" service will be skipped and not started
private static string[] serviceModes = new string[] { "Automatic", "Manual", "Automatic", "Automatic", "Disabled", "Automatic" };

Ofcourse in a normal application the values above should be in a config file and not in the code but this application is just a quick example how to stop, start, enable and disable services.

Below is a link to download a ZIP file with the source code with a Visual Studio 2012 solution; it has examples on how to enable and disable services programatically and also how to enable a service if it is disabled.   I tend to use similar code in my applications that use SQL Server to "heal" itself if a user has accidentally disabled or stopped a service associated with SQL Server.  This is better than allowing the system to bring up a cryptic error message which stops an application from running.

As usual,  I welcome your input and you can email me at comments@paay.us if there is a problem with the code.

You can you can download Registry Monitor here: Download SQLMode