c pound

I reject your reality and substitute my own!
posts - 46, comments - 37, trackbacks - 40

My Links

News

Archives

Image Galleries

Blog Communities

Blog is a stupid word

Lunch Hour

Resources

Monday, March 27, 2006

Find SQL Server instances on your network

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.

posted @ Monday, March 27, 2006 1:58 PM | Feedback (3) |

Powered by: