C# LAN 내 sqlserver 서버 읽기(sqldmo 제외)

4777 단어 sqlserver
using System;
using System.Data.Sql;
using System.Text;

namespace AllSqlServer
{
    class Program
    {
        static void Main(string[] args)
        {
            //SQLDMO.NameList names;
            //SQLDMO.ApplicationClass ac = new SQLDMO.ApplicationClass();
            //names = ac.ListAvailableSQLServers();
            //string[] serverList = new string[names.Count];
            //for (int i = 0; i < serverList.Length; i++)
            //{
            //    serverList[i] = names.Item(i);
            //}
            //foreach (string str in serverList)
            //{
            //    Console.WriteLine(str);
            //}

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

            DisplayData(table);

            Console.ReadLine();
        }

        private static void DisplayData(System.Data.DataTable table)
        {
            foreach (System.Data.DataRow row in table.Rows)
            {
                Console.WriteLine("  = {0}", row["ServerName"]);
                Console.WriteLine("  = {0}", row["InstanceName"]);
                Console.WriteLine("  = {0}", row["IsClustered"]);// Windows SQL Server 
                Console.WriteLine("  = {0}", row["Version"]);//8.* SQL 2000,9.* SQL 2005
                Console.WriteLine("============================");
            }
        }
    }
}

좋은 웹페이지 즐겨찾기