I am trying to get a list of server databases from within my visual studio windows forms project. I am using the following to the a list of available servers and everything works ok:
Dim dataTable = SmoApplication.EnumAvailableSqlServers(False)
datServers.ValueMember = "Name"
datServers.DataSource = dataTable
I am using this code to list all of the databases for the past servers. It works fine and returns all of the databases for some servers but others I get a connection error. All of the severs are SQL server 2008 R2
Dim server As New Microsoft.SqlServer.Management.Smo.Server(xServer)
For Each db As Microsoft.SqlServer.Management.Smo.Database In server.Databases
I can figure out why it works for one sever but not the other.
Any help would be appreciated.