SqlDataSourceEnumerator

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 (127.0.0.1) 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)

{

array.Add(dr[“ServerName”]);

}

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

}

Advertisements

One thought on “SqlDataSourceEnumerator

  1. Ever got an answer / solution for this one? I’m working thru the bit of code myself and it is driving me nuts. Even on MS site there are issues….
    “Due to the nature of the mechanism used by SqlDataSourceEnumerator to locate data sources on a network, the method will not always return a complete list of the available servers, and the list might not be the same on every call. If you plan to use this function to let users select a server from a list, make sure that you always also supply an option to type in a name that is not in the list”

    http://msdn.microsoft.com/en-us/library/system.data.sql.sqldatasourceenumerator.getdatasources.aspx

    However that is of no value to me, I need this or something similar to work and provide me with a list of servers on the network.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s