tags:

views:

389

answers:

2

Hi to all,

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).

We are using the Wix Installer.

What is the correct way to do this?

JD

A: 

Have a look at this question: http://stackoverflow.com/questions/141154/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

M4N
We have seen uninstalls of sql server which have left registry entries around. Also, from a previous post, there is no guarantee that the registry entries will be the same for different versions.
JD
+1  A: 

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.

M4N
@Martin: Thanks, that is exactly what I need. I just now need to get the machine name for the local machine and just check it is in the list. This way I will know whether or not the local machine has a sql instance installed.
JD
@Martin Wouldn't this require that the SQL Browser service be running?
Thomas