c pound

I reject your reality and substitute my own!

  Home  |   Contact  |   Syndication    |   Login
  46 Posts | 0 Stories | 22 Comments | 41 Trackbacks

News

Archives

Image Galleries

Blog Communities

Blog is a stupid word

Lunch Hour

Resources

Monday, March 27, 2006 #

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.