how to get list of sql servers in vb.net

Respons: 0 comments

How to Get List of SQL Server Instants in the Local and Remote in VB.NET

In the following examples, the server instants are stored in Combo Box.
 
Imports System.Data.Sql

Public Sub GetServerList(ByVal cmbServers As ComboBox)

        Dim Server As String = String.Empty
        Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
        Dim table As System.Data.DataTable = instance.GetDataSources()

        For Each row As System.Data.DataRow In table.Rows
            Server = String.Empty
            Server = row("ServerName")
            If row("InstanceName").ToString.Length > 0 Then
                Server = Server & "\" & row("InstanceName")
            End If
            cmbServers.Items.Add(Server)
        Next

        cmbServers.SelectedIndex = cmbServers.FindStringExact(Environment.MachineName)


    End Sub



No comments:

Post a Comment

Copyright © MS SQL MS-ACCESS

Sponsored By: GratisDesigned By: Habib Blog