c pound

I reject your reality and substitute my own!

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

News

Archives

Image Galleries

Blog Communities

Blog is a stupid word

Lunch Hour

Resources

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 on Monday, March 27, 2006 1:58 PM

Feedback

# re: Find SQL Server instances on your network 4/30/2006 6:59 AM John R
Hi,
I'm not finding SQLServer as a type or namespace. Can you post where it is to be found. Thanks.
John

# re: Find SQL Server instances on your network 5/1/2006 5:49 AM Dan Koster
Sorry John,
I should have mentioned that SQLServer is just a simple class I created to hold the server information and publish a ToString function so I could just drop it into a list-box.

public class SQLServer
{
public string Name;
public string InstanceName;
public string IsClustered;
public string Version;

public override string ToString()
{
return Name;
}
}

I removed the comments from the above code, so look here for a description of the fields : http://msdn2.microsoft.com/en-us/library/system.data.sql.sqldatasourceenumerator.getdatasources.aspx

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 8 and 6 and type the answer here: