Retrieve SQL Server instance name from network in C# and VB.Net

on Oct 17, 2019 12:23 AM

Retrieving SQL Server instance name from network using C# 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Oct 17, 2019 01:15 AM

Hi Saiansh,

Use SqlDataSourceEnumerator class to get the SQL Server instances within the current network.

This returned table contains a list of server instances available on the network.

The table returned from the method call contains the following columns.

ServerName Name of the server.
InstanceName Name of the server instance. Blank if the server is running as the default instance.
IsClustered Indicates whether the server is part of a cluster.
Version Version of the server.

Check this example. Now please take its reference and correct your code.


System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();


Dim instance As System.Data.Sql.SqlDataSourceEnumerator = System.Data.Sql.SqlDataSourceEnumerator.Instance
Dim table As System.Data.DataTable = instance.GetDataSources()

For more details refer below link.

SQL Server Instances