Retrieving SQL Server 2005 Database Info Using SMO: Basics - Connecting to the SQL Server database using SMO
(Page 3 of 5 )
After completing all the steps in the previous section, create a layout with only a button (“btnConnect”) and multi-lined text box as shown in the following inage (Fig 3):

Now, it is the time to write some code! Let us switch to the code window (by pressing F7) and modify as shown below:
Imports Microsoft.SqlServer.Management.Smo
Public Class Form1
Private Sub btnConnect_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnConnect.Click
Dim svr As Server = New Server()
Me.TextBox1.Text = "Server Name: " & svr.Name &
ControlChars.NewLine
Me.TextBox1.Text &= "Instance Name: " & svr.InstanceName
& ControlChars.NewLine
Me.TextBox1.Text &= "Product: " & svr.Information.Product
& ControlChars.NewLine
Me.TextBox1.Text &= "Version: " &
svr.Information.VersionString & ControlChars.NewLine
Me.TextBox1.Text &= "Edition: " & svr.Information.Edition
& ControlChars.NewLine
Me.TextBox1.Text &= "Default Language: " &
svr.Information.Language & ControlChars.NewLine
End Sub
End Class
That’s it. You are finished. Execute the solution by pressing F5. Once you click on the “Connect” button, it should connect to the default instance of SQL Server and retrieve information as shown in the following image (Fig 4):

Next: Understanding the SMO connectivity >>
More MS SQL Server Articles
More By Jagadish Chaterjee