C#列出局域网中可用SQL Server服务器(续)
程序员文章站
2022-12-02 11:59:08
using system; using system.data.sql; using system.text; namespace...
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("============================");
}
}
}
}
文章引用自: