tags:

views:

79

answers:

1

I am trying to enumerate all SQL Server instances installed on a local machine. I am using SmoApplication.EnumAvailableSqlServers(true). However, only SQL Server Express 2005 instances are shown. Default 2008 instance is not shown at all!

I tried 2 other solutions with SqlServerRegistrations.EnumRegisteredServers() and SqlDataSourceEnumerator.Instance.GetDataSources() but they do not work either.

There is another question regarding this (http://stackoverflow.com/questions/1433435/cant-enumerate-sql-server-2008-registered-servers-with-smo) but it unfortunately has no answer.

+1  A: 

Here's another alternative you could try using the ManagedComputer Class (Namespace: Microsoft.SqlServer.Management.Smo.Wmi).

ManagedComputer mc = new ManagedComputer();

foreach (ServerInstance si in mc.ServerInstances)
{
      Console.WriteLine(si.Name);
}
Joe Stefanelli
I tried that - yesterday as it happens - and it returns no instances at all!! If you have any idea why, please let me know! (My envt is Win7, SQL05/08, VS2010)
ChrisA
Thank you, Joe!
Alex
@Alex: Did this technique work for you?
Joe Stefanelli
@Joe - yes, it returns default instance of 2008 SQL server, however, nothing about 2 instances of 2005 server. So I have to do some hybrid search using various methods.
Alex