Check if SQL server (any version) is installed?
A simple way to list all SQL Servers on the network is this:
using System.Data;
using System.Data.Sql;
using System;
...
SqlDataSourceEnumerator sqldatasourceenumerator1 = SqlDataSourceEnumerator.Instance;
DataTable datatable1 = sqldatasourceenumerator1.GetDataSources();
foreach (DataRow row in datatable1.Rows)
{
Console.WriteLine("****************************************");
Console.WriteLine("Server Name:"+row["ServerName"]);
Console.WriteLine("Instance Name:"+row["InstanceName"]);
Console.WriteLine("Is Clustered:"+row["IsClustered"]);
Console.WriteLine("Version:"+row["Version"]);
Console.WriteLine("****************************************");
}
Taken from this blog post.
Another simple alternative would be to use the following command line inside your installer:
sc queryex type= service | find "MSSQL"
The command above simply lists the all the services containing the MSSQL part, listing named and default SQL Server instances. This command returns nothing if nothing is found. It returns something like this:
SERVICE_NAME: MSSQL$SQLEXPRESS
Hope this helps.
Have a look at this question: How can I determine installed SQL Server instances and their versions?
One of the answers lists the registry keys you could check to determine the installed SQL Server version(s).
Or check this codeproject article if you need to find any SQL Servers in the local network: http://www.codeproject.com/KB/database/locate_sql_servers.aspx