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