Querying for possible SQL server databases

  • Thread starter Thread starter Simon Jefferies
  • Start date Start date
S

Simon Jefferies

Hello,

How do I query for available SQL server databases on the network?

I'm looking to do a combobox with a list of available databases that are
available that can be connected to?

TIA
Simon Jefferies
Tools Programmer,
Headfirst Productions
 
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q287737&

1. Reference COM "Microsoft SQLDMO Object Library"

2. Ensure you have SQL Service Pack 2 or later installed

loads SQL server names into combo 'cbSQLServerName' ...

Private Sub PopulateSQLServerNames()
Try
Dim iTemp As Int16
Dim oNames As SQLDMO.NameList
Dim oSQLApp As SQLDMO.Application
oSQLApp = New SQLDMO.Application()

oNames = oSQLApp.ListAvailableSQLServers
Me.cbSQLServerName.Items.Clear()
For iTemp = 1 To oNames.Count
Me.cbSQLServerName.Items.Add(oNames.Item(iTemp))
Next iTemp
oNames = Nothing
oSQLApp = Nothing
If cbSQLServerName.Items.Count > 0 Then
cbSQLServerName.SelectedIndex = 0

Catch ex As Exception
MessageBox.Show(ex.Message & ControlChars.NewLine &
ControlChars.NewLine & ex.ToString)
End Try

End Sub
 
Back
Top