Previously, the discovery of what SQL servers exist on your network was quite a task. The general approach involved PInvoke. Yeah. Now, it .Net 2, it's a one-liner. Sweet!
public
List<SQLServer> GetServers()
{
DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();
List<SQLServer> servers = new List<SQLServer>();
foreach(DataRow row in dt.Rows)
{
SQLServer svr = new SQLServer();
svr.Name = row.ItemArray[0] as string;
svr.InstanceName = row.ItemArray[1] as string;
svr.IsClustered = row.ItemArray[2] as string;
svr.Version = row.ItemArray[3] as string;
servers.Add(svr);
}
return servers;
}
Hmm... I just noticed that they used a singleton with one method instead of just making GetDataSources static. Odd.