Para sacar la lista de servidores, conectar al servidor y sacar el listado de BBDD:
Public CONN As New ADODB.Connection
Private Sub ObtenerListadoServidores()
Dim ServidoresSQL As SQLDMO.Application
Dim ListaServers As NameList
Dim i As Integer
Set ServidoresSQL = New SQLDMO.Application
Set ListaServers = ServidoresSQL.ListAvailableSQLServers
For i = 1 To ListaServers.Count
Servidor_SQL.AddItem ListaServers.Item(i)
Next
Servidor_SQL.ListIndex = 0
Set ListaServers = Nothing
End Sub
Private Sub Conectar_SQL()
On Error GoTo error_Conexion
Set CONN = Nothing
CONN.Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=" & Servidor_SQL)
Databases
Exit Sub
error_Conexion:
If Err.Number = -2147217843 Then
MsgBox "El usuario no existe o no tiene una conexión de confianza. Descripción: " & Err.Description, vbCritical
Else
MsgBox Err.Number & ". " & Err.Description
End If
End Sub
Private Sub Databases()
Dim rs_BBDD As ADODB.Recordset
BBDD.Clear
Set rs_BBDD = New ADODB.Recordset
Set rs_BBDD = CONN.Execute("sp_databases")
If Not rs_BBDD.EOF Then
Do Until rs_BBDD.EOF
BBDD.AddItem (rs_BBDD.Fields("Database_Name"))
rs_BBDD.MoveNext
Loop
rs_BBDD.Close
BBDD.Enabled = True
End If
Set rs_BBDD = Nothing
BBDD.ListIndex = 0
BBDD.Enabled = True
End Sub
Private Sub BBDD_DblClick()
CONN.Close
Set CONN = Nothing
CONN.Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=" & Servidor_SQL & "Initial Catalog=" & BBDD.Text)
End Sub
Referencias necesarias:
Microsoft SQLDMO Object Library
Microsoft ActiveX Data Object 2.7 Library (en mi caso)</li>
Espero que te sirva de ayuda,
Saludos.