Simple Backup/Restore Utility With SQL-DMO Using VB.NET - Programming SQL-DMO using .NET
(Page 3 of 5 )
As specified above, SQL-DMO comes as a COM interface (unmanaged). It can be used with any OLE automation controller as a development platform. Now we shall see how to work with VB.NET and SQL-DMO using Visual Studio.NET 2003 Enterprise Architect as the main objective. Working with VC#.NET is also quite similar to the steps we will discuss now (except for the syntactical differences in programming statements).
Using Visual Studio.NET, proceed with following steps:
- Go to File >> New >> Project
- From the New Project Dialog, select Visual Basic Projects as Project Type and select Windows Application as Project Template (Figure 1).
Figure 1 - Provide ‘SQLDMOSample’ as name of the project as shown in Figure 1. (In case of C#, select Visual C# Projects accordingly).
- Drag a button from toolbox. Go to the properties of that button and ‘name’ it as btnCheck and change ‘text’ property to Check Connectivity.
- Go to Project Menu and click on Add Reference as in Figure 2.
Figure 2 Click on the
COM tab, search for
Microsoft SQL DMO Object Library, double-click on it and click
OK as in Figure 3. You should see SQLDMO as a reference in Solution Explorer as in Figure 4.
Figure 3
Figure 4- In the click event of btnCheck copy the following code. You need to change instance name, User ID and Password according to your configuration.
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
Dim oSQLServer As New SQLDMO.SQLServer
oSQLServer.Connect("instanceName", "UserID", "Password")
MessageBox.Show("Connected Successfully")
oSQLServer.DisConnect()
MessageBox.Show("Disconnected Successfully")
End Sub
So, finally you tested the connectivity to SQL Server 2000 instance using SQL-DMO object SQLServer.
Next: Backup/Restore utility using SQL-DMO with .NET >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|