2

Anyone know if there is a more "up to date" way of enumerating all available SQL Server instances via .Net, i.e. without using System.Data - DataTable/DataRow bits.

SqlDataSourceEnumerator sqlEnumerator = SqlDataSourceEnumerator.Instance;
DataTable dt = sqlEnumerator.GetDataSources();
foreach(DataRow row in dt.Rows)
{
    Console.WriteLine(row["ServerName"]);
    Console.WriteLine(row["InstanceName"]);
    Console.WriteLine("*******************************");
}
Simon Fox
  • 10,409
  • 7
  • 60
  • 81
  • possible duplicate of [How to list available instances of SQL Servers using SMO in C#?](http://stackoverflow.com/questions/1130580/how-to-list-available-instances-of-sql-servers-using-smo-in-c) – JohnFx Jun 17 '10 at 22:43
  • @JohnFx I did see that but I'd like to avoid a dependency on SMO if possible – Simon Fox Jun 17 '10 at 23:42

1 Answers1

3

You can find several answers here.

Community
  • 1
  • 1
Restuta
  • 5,855
  • 33
  • 44