If you donβt want to bind to SQL SMO, as Benβs article uses , you can do something like this to find all the SQL servers on your network:
Private Sub cmbServer_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbServer.DropDown
Dim oTable As Data.DataTable
Dim lstServers As List(Of String)
Try
If cmbServer.Items.Count = 0 Then
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
oTable = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources
For Each oRow As DataRow In oTable.Rows
If oRow("InstanceName").ToString = "" Then
cmbServer.Items.Add(oRow("ServerName"))
Else
cmbServer.Items.Add(oRow("ServerName").ToString & "\" & oRow("InstanceName").ToString)
End If
Next oRow
End If
Catch ex As Exception
ErrHandler("frmLogin", "cmbServer_DropDown", ex.Source, ex.Message, Ex.InnerException)
Finally
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
If oTable IsNot Nothing Then
oTable.Dispose()
End If
End Try
End Sub
SqlDataSourceEnumerator , SQL- 2.0.