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

Last Reply 4 months ago By dharmendr

Posted 4 months ago

Retrieving SQL Server instance name from network using C# 

You are viewing reply posted by: dharmendr 4 months ago.
Posted 4 months ago

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.

C#

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

VB.Net

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