How do I get a list of SQL Servers available on my network?

I’m trying this but I’m not sure how to proceed. Can you give me a hand?

SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
DataTable table = instance.GetDataSources();

foreach (var row in table.Rows)
     foreach (var column in table.Columns)

Where ??? = SQL Server Name.

  • Transposing a table with SQL
  • Uploading a file into SQL Server
  • Best way to do nested case statement logic in SQL Server
  • How do I add a new replicated table to a SQL Server 2005 DB that is in merge replication?
  • How to improve data insert/update performance?
  • How would I go about extracting the sql server name from the table?

    I’m working in ASP .NET with C#.

  • Stored procedure output parameter c#
  • Pro & Cons of storing files(pictures) in a SQL Server for a website
  • Differentiating between 2 SQL column names with the same name in a C# SqlConnection
  • Change SSRS data source of report programmatically in server side
  • One Cache for various Applications?
  • ADONET async execution - connection broken error
  • One Solution collect form web for “How do I get a list of SQL Servers available on my network?”

    Well, if wanted to see all available information, you can iterate over the columns available:

    DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();
    foreach (DataRow dr in dt.Rows)
        foreach (DataColumn col in dt.Columns)
            Console.WriteLine("{0,-15}: {1}", col.ColumnName, dr[col]);

    Which would show something like:

    ServerName     : COMPUTER1
    InstanceName   : SQLEXPRESS
    IsClustered    : No
    Version        : 9.00.4035.00

    So, to answer your question:


    Full Code:

    DataTable table = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
    foreach (DataRow server in table.Rows)
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.