Dim i As Integer
Dim sqlApp As New SQLDMO.Application
Dim ServerName As SQLDMO.NameList
Set ServerName = sqlApp.ListAvailableSQLServers
For i = 1 To ServerName.Count
Combo1.AddItem ServerName.Item(i) '列出可用的服务器
Next
Dim oServer As New SQLDMO.SQLServer
oServer.Connect "(local)", "sa", "sapowd" ‘’运行出错,如下图
Dim db As SQLDMO.Database
For Each db In oServer.Databases
Combo2.AddItem db.Name '列出所有的数据库
Next