using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;

namespace EnumDS
{
   class Program
   {
      static void Main(string[] args)
      {
         DbProviderFactory factory =
            DbProviderFactories.GetFactory("System.Data.SqlClient");
         DbConnection conn = factory.CreateConnection();
         conn.ConnectionString =
            @"data source=.\SQLExpress; initial catalog=SampleDB; Integrated Security=SSPI;";
         conn.Open();

         if (factory.CanCreateDataSourceEnumerator)
         {
            DbDataSourceEnumerator dsEnum = factory.CreateDataSourceEnumerator();
            DataTable sources = dsEnum.GetDataSources();
            foreach (DataRow dataSource in sources.Rows)
            {
               Console.WriteLine(dataSource["ServerName"]);
            }
         }
         Console.ReadLine();
      }
   }
}
