C#列出局域網中可用SQL Server服務器(續(xù))
更新時間:2008年04月06日 22:48:21 作者:
上一篇文章展示了使用COM對象如何列出局域網中的 SQL Server服務器信息,后來還發(fā)現(xiàn)在.Net中有現(xiàn)成的類可用,而不需要使用不太熟悉的COM對象了,這樣豈不是更好?下面我把代碼展示給大家:
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("============================");
}
}
}
}
文章引用自:
相關文章
.Net行為型設計模式之職責鏈模式(Chain of Responsibility)
這篇文章介紹了.Net行為型設計模式之職責鏈模式(Chain of Responsibility),文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05.Net創(chuàng)建型設計模式之工廠方法模式(Factory?Method)
這篇文章介紹了.Net設計模式之工廠方法模式(Factory?Method),文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05