Introduction to SQL Server Shared Management Objects (SMO)
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Public Class
Form1
Public Sub LoadDB()
'Declare an instance of the Server Class along with the Connection
String
Dim Mysvr As
New Server(".\SQLEXPRESS")
'Declare a Database Variable that will enumerate in the TreeView
Dim db As
New Database
'Now iterate through the list of databases within the server
For
Each db In Mysvr.Databases
'We are now going to populate the TreeView Nodes with
the Databases
TreeView1.Nodes.Add(db.Name)
Next
End Sub
Private Sub Form1_Load(ByVal sender As
System.Object,
ByVal e
As System.EventArgs)
Handles MyBase.Load
Try
LoadDB()
Catch ex As
SqlServerManagementException
MessageBox.Show("Error" + ex.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
End
Try
End Sub
End Class
End of Technical Article
SQL Server Club is a free community service from Norb Technologies - Making SQL Server Faster - www.norbtechnologies.com