c sharp lists the SQL Server servers available on the LAN
- 2020-05-06 11:49:24
- OfStack
SQLDMO is provided by SQLDMO.dll, which comes with Microsoft SQL Server. Since SQLDMO.dll is an COM object, you must add a reference to it in the.NET project before using it. Note to add the COM reference, find "Microsoft SQLDMO Object Library (possible path: system disk :\Program Files\Microsoft SQL Server\80\Tools\Binn\ sqldmo.dll)" and click ok to add the reference.
The following is a class in C# to list Microsoft SQL Server available on a LAN:
using System;
using System.Collections.Generic;
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);
}
Console.ReadLine();
}
}
}