Check if SQL server (any version) is installed?

I need to find if SQL server is installed on a machine. It could be any version of SQL server (7, 2005,8, sql express etc). We need to know this information as we are writing an installer and need to show to the user that if SQL server has not been found, the installation cannot proceed.

I have seen versions that use the registry, wmi, SMO or simply just connect to SQL server instance (although would not help here as we do not know the server name).

  • FreeTDS working, but ODBC cannot connect
  • Calculate time duration between differents records in a table based on datetimes
  • Copy Multiple Tables into ONE Table (From Multiple Databases)
  • SQL Server How to Find the customers who have bought a product from EACH store?
  • Most efficient way to move table rows from one table to another
  • Is there a solution for getting the default value of the parameters of a given stored procedure?
  • We are using the Wix Installer.

    What is the correct way to do this?


  • SQL c# determining type of sql server
  • Removing dups and updating null values
  • Can't figure out where does the stored procedure save the data
  • why can't I access my CTE after I used it once?
  • family tree sql query
  • Connecting to MSSQL with Codeigniter PHP
  • 4 Solutions collect form web for “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("Server Name:"+row["ServerName"]);
        Console.WriteLine("Instance Name:"+row["InstanceName"]);
        Console.WriteLine("Is Clustered:"+row["IsClustered"]);

    Taken from this blog post.

    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:

    I needed something similar, to discover a local SQLServer instance to perform automated tests against.

    The SmoApplication was perfect for this requirement – my code looks like this:

    public static string GetNameOfFirstAvailableSQLServerInstance()
        // Only search local instances - pass true to EnumAvailableSqlServers
        DataTable dataTable = SmoApplication.EnumAvailableSqlServers(true);
        DataRow firstRow = dataTable.Rows[0];
        string instanceName = (string)firstRow["Name"];
        return instanceName;

    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:


    Hope this helps.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.