I was just working on a small application in Visual Studio 2005, I am using the SqlDataSourceEnumerator which is new in Framework 2.0 and enumerates all the instances of SQL Server 2000 and SQL Server 2005 on the network, following is my function from my class.

The interesting thing is that SqlDataSourceEnumerator does enumerates all servers including the SQL Server on my local machine when I am connected to the network, but if I am not connected to a network, it does not even get my local SQL Server. This is quite strange, because even if the API it works for the network it should check the loopback ( network.

I know I can solve this by using the SQLDEMO API’s to get the SQL Servers as we have been doing in 1.1, but still am looking for the answer for the behavior of SqlDataSourceEnumerator

public string[] GetAllServerNames()


ArrayList array = new ArrayList();

SqlDataSourceEnumerator dse = SqlDataSourceEnumerator.Instance;

DataTable dt = dse.GetDataSources();

foreach (DataRow dr in dt.Rows)




return (string[])array.ToArray(typeof(string));