Available SQL Server list

  • Thread starter Thread starter Guest
  • Start date Start date
You need to import SQLDMO in your project. The following function adds the
list of servers to a combo box - cboServers and returns the count:

Imports SQLDMO

.....

Private Function LoadSQLServerList() As Integer
Dim serverIndex As Integer
Dim sqlServers As SQLDMO.NameList
Dim sqlServer As Object

' Get a list of servers
sqlServers = New SQLDMO.Application().ListAvailableSQLServers()

' Iterate through the server names, and add it to the combobox
For Each sqlServer In sqlServers
If Not sqlServer Is Nothing Then
cboServers.Items.Add(sqlServer)
End If
Next

' Send back the count of servers
LoadSQLServerList = cboServers.Items.Count
End Function

Hope that helps.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com


EvanK said:
Is there a way to access a list of available sql servers in vb and make a
dropdown list?
 
You could create a method/routine that would return the results of:

SELECT Name FROM sysdatabases ORDER BY <your choice, Name, ID>

and fill another combobox with it..or listbox...or wheva!

HTH
-Rich

EvanK said:
Great - it worked fine - thanks. Now is there a way to list the
databases?
 
Oops....make sure you hit the Master database

SELECT Name FROM Master..sysdatabases


EvanK said:
Great - it worked fine - thanks. Now is there a way to list the
databases?
 
Continuing the previous example:

Dim sqlServer As SQLDMO.SQLServer
Dim sqlDB As Object

sqlServer = New SQLDMO.SQLServer()
Try
' Connect to your database with userID and password
sqlServer.Connect(cboServers.Text, txtUserID.Text,
txtPassword.Text)

' Check for database names in the server
' This loop adds the database name to another combobox
For Each sqlDB In sqlServer.Databases
If Not sqlDB.Name Is Nothing Then
cboDatabases.Items.Add(sqlDB.name)
End If
Next
Catch Exp As Exception
MsgBox(Exp.ToString)
End Try


--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com


EvanK said:
Great - it worked fine - thanks. Now is there a way to list the
databases?
 
It seems that when I install this application using the listavailableqlservers function I get an unhandled exception error. I tried a TRY statement surrounding it but to no avail. ANy suggestions?
 
Back
Top