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); }
Nicely put together thanks for sharing.