How to bind datatable with all Sql Instance names within Network and Local in .Net

By the help of following code you can get all Sql instance with in Local or Network in your Datatable Object so that you can easily display these instances to user.

First you need to add following references-
Microsoft.SqlServer.ConnectionInfo
Microsoft.SqlServer.Management.Sdk.Sfc
Microsoft.SqlServer.Smo

[vb.net]
import Microsoft.SqlServer.Management.Smo with the help of ‘Imports’ keyword in code file

Imports Microsoft.SqlServer.Management.Smo

and use code:

    Private Sub Getdatatables()
        'Get all Network Instance
        Dim dataTable1 As System.Data.DataTable = SmoApplication.EnumAvailableSqlServers(False)
 
        'Get all Local Instance
        Dim dataTable1 As System.Data.DataTable = SmoApplication.EnumAvailableSqlServers(True)
    End Sub

[C#]

import Microsoft.SqlServer.Management.Smo with the help of ‘Using’ keyword in code file

Using Microsoft.SqlServer.Management.Smo;

and use this code:

private void Getdatatables()
{
	//Get all Network Instance
	System.Data.DataTable dataTable1 = SmoApplication.EnumAvailableSqlServers(false);
 
	//Get all Local Instance
	System.Data.DataTable dataTable1 = SmoApplication.EnumAvailableSqlServers(true);
}

Author: Ankur

Have worked primarily in the domain of Calling, CRM and direct advertisers services. My technological forte is Microsoft Technologies especially Dot Net (Visual Studio 2003, 2005, 2008, 2010 and 2012) and Microsoft SQL Server 2000,2005 and 2008 R2. My Area of Expertise is in C#. Net, VB.Net, MS-SQL Server, ASP. Net, Silverlight, HTML, XML, Crystal Report, Active Reports, Infragistics, Component Art, ComponeOne, Lead Tools etc.

One thought on “How to bind datatable with all Sql Instance names within Network and Local in .Net”

Comments are closed.