I need to search for all the SQL Server / SQL Server Express instances installed in a newtwork and display them in a combo box in a C# Application Program.
I tried the following two codes:
But both the methods doesn't give me the results I'm hoping for.
My primary objective is to distinguish between SQL Server 2005 and SQL Server Express, because for another program to run I need my user to be able to select one among those two. But when I run this code it give the following errors:
1) I have above both installed on my computer, but it gives only the server name of SQL Server 2005.
2)On the network, this code completely ignores some of the machines, and it DOES give me both the SQL Server 2005 and Express instances on some other machines on my network. If I run the code from another machine, it still doesn't show that I ahve installed both on my computer.
Experts, please help on this.
//Here, localOnly is a bool variable. If true, this method search only the instances on this machine and if set to false search instances on all machines on the network
foreach (DataRow serverRow in SmoApplication.EnumAvailableSqlServers(localOnly).Rows)
//Here ItemArray stores each SQL server name and ItemArray stores each instance
SqlDataSourceEnumerator sqlInstance = SqlDataSourceEnumerator.Instance;
foreach (DataRow dataSourceRow in sqlInstance.GetDataSources().Rows)
cmbServerList.Items.Add(dataSourceRow.ItemArray + "/" + dataSourceRow.ItemArray);