Simple Backup/Restore Utility With SQL-DMO Using VB.NET - Backup/Restore utility using SQL-DMO with .NET
(Page 4 of 5 )
This is a very simple utility to take a backup of an entire specified database and restore it whenever needed using just two buttons, two labels and a progress bar on the windows form. Even though I hard coded some parameters such as instance name, user id, password, file name, database name, and so on, you can further extend this utility to present a better UI so that the tool accepts everything from the user dynamically. Make sure that my focus basically is not on UI, but on using SQL-DMO with a simple little code. I hope you agree with me.
The utility basically contains only a single tiny windows form with the following controls on it:
- LblMessage to provide status messages like ‘Backup process started..’ etc.
- LblPercent to provide the status of process operation (backup/restore) in the form of a percentage value.
- ProgressBar1 to provide the status of a process operation (backup/restore) in a fancy way i.e., just for a better appearance.
- BtnBackup to start the process of Backup Operation.
- BtnRestore to start the process of Restore Operation
The following are the main declarations of SQL-DMO objects used:
Dim oSQLServer As New SQLDMO.SQLServer
Dim WithEvents oBackup As New SQLDMO.Backup
Dim WithEvents oRestore As New SQLDMO.Restore
oSQLServer is used to connect to SQL Server instance, oBackup to work with the backup operation and oRestore to work with the restore operation. The word WithEvents raises the respective PercentComplete (gives the progress) event of either oBackup or oRestore objects, when either of them is in the process of operation.
The following are the hard-coded constants used as main parameters:
Const _INSTANCE As String = "."
Const _USER As String = "sa"
Const _PWD As String = ""
Const _BACKUPFILE As String = "c:NorthwindBackup.bkp"
Const _DATABASE As String = "Northwind"
_INSTANCE specifies instance name (in this context localhost). _USER specifies the userid to logon to instance with the respective password specified using _PWD. The entire backup is taken into an incremental backup file (every backup gets added to an already existing backup, but within that same file) specified using _BACKUPFILE. The restore process gets the latest backup within the same backup file. The backup and restore operations work on the database specified with _DATABASE.
The main backup or restore processes are explained on the next page.
Next: Understanding Backup and Restore processes >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|