This is a very short code snippet where I will explain how to list the SQL Server instances that are installed on your machine and on the network connected to your machine.

You will need to import the following namespaces


using System.Data;
using System.Data.Sql;

Imports System.Data
Imports System.Data.Sql

SqlDataSourceEnumerator class
The SqlDataSourceEnumerator class allows you to get the Instances of the SQL Server installed on the machine and also on the network the machine is connected to. You can find more information on the same on the following MSDN article
Now here I’ll get the installed instances of the SQL Server and bind them to a DropDownList Control
DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();
foreach (DataRow dr in dt.Rows)
    ddlInstances.Items.Add(string.Concat(dr["ServerName"], "\\", dr["InstanceName"]));

Dim dt AsDataTable = SqlDataSourceEnumerator.Instance.GetDataSources
ForEach dr As DataRow In dt.Rows
     ddlInstances.Items.Add(String.Concat(dr("ServerName"), "\\", dr("InstanceName")))

List installed SQL Server instances on machine and network using C# and VB.Net

That’s it in this article. Hope you liked it.