Enumerating the databases on a server in SQLDMO/vb.net
Whilst you could just execute the following TSQL command:
select name from master..sysdatabases
to obtain the list of databases on a SQL Server box, it's far more fun to try and do it the SQLDMO way ;) Which is....
Dim oSqlServer as SQLDMO.SQLServer2 = New SQLDMO.SQLServer2Class
Dim oSqlServerDB as SQLDMO.Database
oSqlServer.Connect("ServerName", "SQL_Login_Name, "SQL_Password")
For Each oSqlServerDB In oSqlServer.Databases
MessageBox.Show(oSqlServerDB.Name)
Next
I've used MessageBox.Show to output the database names, but I could've just as easily have pushed the details of each database into an ArrayList or other collection and returned the information as the output of a function. Another way of writing the above code (not as easy to read it has to be said! Well, not as "OOP" anyway!) is:
For i As Integer = 1 To m_oSqlServer.Databases.Count
MessageBox.Show(m_oSqlServer.Databases.ItemByID(i).Name)
Next
And that, pretty much, is how to enumerate the databases on a SQL Server via SQLDMO