ADO Net C# Tutorial

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
    class Program
    {
        static void Main(string[] args)
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
            DbConnection conn = factory.CreateConnection();
            conn.ConnectionString = "data source=localhost; 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"]);
                }
            }
            
        }
    }