Click here to Skip to main content
14,601,387 members

SQL Server Database Backup Utility using VB.NET and SQL-DMO (New version)

Rate this:
4.77 (26 votes)
Please Sign up or sign in to vote.
4.77 (26 votes)
17 Mar 2008CPOL
A Windows application to backup and restore SQL server tables,views,user defined functions and stored procedures

New Release (1.1.0)

It has been a year since I wrote this article. I got many responses for this backup utility. So I decided to update this program and made major changes to make it more stable in terms of functionality and performance. You can read my original article, SQL Server Backup Utility (Old Version).

Following is a list of changes for a new version:

  • Backup file extension is now .ZIP instead of .SQLBackup. This is to avoid any confusion.
  • Old version was having an issue with restoring data in certain conditions. It should have been fixed in this version.
  • Multi threading is added with backup and restore processes. This way, the program won't freeze during long operations.
  • UI is improved to display proper status of backup and restore.
  • Included GNU license.

I will be doing more updates to this program in the next few days. Please check my Website,, regularly to get the latest source.


Whenever we want to backup or move the SQL Server database, most of us prefer to use a regular backup utility which is available through Enterprise Manager in SQL Server 2000 or Management Studio in SQL Server 2005. The limitation of using Enterprise Manager or Management Studio is that we have to use either complete or differential backups. This is a very tedious task when we want to backup only a small portion of a large database. For example, in my database I would like to take a backup of only 15 tables out of 100 tables or I may want to backup only a few records from these selected tables. For that reason, I was looking for a small utility which allows me to do so. After searching through hundreds of utility programs, I have decided to write my own utility.


  • Backup of selected objects
  • Backup of selected data
  • Backup of only scripts
  • Backup of only data
  • Backup of both scripts and data
  • Supports backup from remote severs over Web, LAN or even local PC

Using Program

Image 1

To backup the database,

  • Open the database backup window from tools menu.
  • Enter server name, database name, user name and password for SQL Server.
  • Click on Connect. This will display all available tables, views, stored procedures, user defined functions, user defined datatypes and users from database.
  • If you want to backup only data, check Backup Data and remove checkmark from Backup object structures (Scripts).
  • If you want to backup only scripts, check Backup object structures (Scripts) and remove checkmark from Backup Data.
  • Select objects that you want to backup from list. By default, all objects are selected. In the above picture, Adv_StackedBar2 and Adv_UserRoleTypes tables will be excluded from backup.
  • Apply any condition on table data. For example UserID > 10 and UserID < 25 in the above picture. It means only those records will be exported which satisfy this condition.
  • Modify number of rows to export on a particular 'table'. For example, in the above picture Top 20 *, means only top 20 rows will be exported for Adv_TodaysOutlook table.
  • Click on Start Backup. It will ask you to enter a file name and location. Note that backup file has extension *.zip. Remember that this is not a standard SQL server backup file. It's just a zip file which contains scripts for tables, views, stored procedures etc. It also includes data in row (*.dat) files.

To restore the backup,

  • Open Database restore window from tools menu.

Image 2

  • Enter server name, database name, user name and password for SQL Server.
  • Select database backup file (*.zip) that you want to restore. Remember this utility can only restore those backup files (*.zip) which are created by this utility itself. It cannot restore regular SQL server backup files.
  • When you select backup file, it displays all objects available in backup.
  • If you want to create a new database, check Create New Database option.
  • If you want to drop the existing database and recreate it, check Drop Existing Database option.
  • Select objects that you want to restore from list. By default all objects are selected.
  • Click on Start Restore.

Using Other Features

As you can see, both backup and restore forms include Preset combo box. What it does is it records server name, database name, user name and password information every time you backup or restore a database. Next time when you want to use the same server, you don't need to enter all these parameters again. You can select it from Preset combo list. It also remembers last accessed SQL server name.

Using Code

I am not writing the description of code in much detail. Most of the code is self explanatory and commented. Just a few quick notes. I have used SQL-DMO library for all database related tasks. For SQL-DMO library, either SQL Express or SQL Server 2000 client tools must be installed on your computer.

Objects from SQL-DMO Library

'Server object from SQL-DMO library
Dim oServer As New SQLServer2
'Database object from SQL-DMO library
Dim db As SQLDMO.Database2
'BCP Utility from SQL-DMO Library
Dim objBCP As New SQLDMO.BulkCopy2

Function for Exporting Data to a File from SQL Server

objBCP.DataFilePath = "c:\temp\EmployeeData.dat"

Generating SQL Script for an SQL Server Object

'Generate script with drop statement
Dim SQL as String = db.GetObjectByName("Employee").Script_
(SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops) + db.GetObjectByName("Employee").Script()


  • This utility cannot take backup of user roles and triggers.
  • Backup file is in zip format. (You can extract it using winzip or another zip utility and view its content.). It cannot be restored using SQL Server Enterprise Manager.


This program can be enhanced further to include a Windows service which can take regular backups for SQL Server without user interactions. Thus this utility can be utilized for your regular backups.


I have used SharpZipLib (ICSharpCode.SharpZipLib.dll), a free open source zip utility library available here, for zipping backup directory. This file is included in Bin\Release folder.


  • Visual Studio .NET 2005 (For source code)
  • .NET Framework 2.0
  • Microsoft SQL Server 2000 or Microsoft SQL Express 2005 or Microsoft SQL Server 2005 client components (For SQL-DMO Library)

How to Install Utility

Make sure that you have either SQL Server 2000 or 2005 client components installed on your computer. If you do not want to install these components, you can install Microsoft SQL Server 2005 Backward Compatibility Components. These components are needed for SQL-DMO library.

Download the setup zip file from the link provided at the top of this article. Extract and run setup.exe. It should create icons in your programs menu and desktop.

How to Use the Source Code

Download the source code zip file from the link provided at the top of this article and run DatabaseBackup.sln solution file with Visual Studio 2005.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shabdar Ghata
Web Developer
Canada Canada
Software Developer

Comments and Discussions

GeneralMy vote of 5 Pin
Darshan Yadav india26-Dec-13 22:41
MemberDarshan Yadav india26-Dec-13 22:41 
QuestionPlease help Pin
pickatshou4-Feb-13 1:51
Memberpickatshou4-Feb-13 1:51 
GeneralMy vote of 5 Pin
whomwhom8-Jun-12 5:30
Memberwhomwhom8-Jun-12 5:30 
GeneralMy vote of 5 Pin
desaihardikj@gmail.com22-Sep-11 18:36
Memberdesaihardikj@gmail.com22-Sep-11 18:36 
QuestionCan't Get it to run in VS2010 on Windows 7 Pin
BHort15-Sep-11 11:21
MemberBHort15-Sep-11 11:21 
AnswerRe: Can't Get it to run in VS2010 on Windows 7 Pin
Braks14-Dec-11 2:59
professionalBraks14-Dec-11 2:59 
QuestionColumn names with spaces Pin
petebob7969-Jul-11 12:48
Memberpetebob7969-Jul-11 12:48 
GeneralMy vote of 5 Pin
pandeypavankumar27-Apr-11 17:24
Memberpandeypavankumar27-Apr-11 17:24 
General"error r6034 with sql backup/restore utility by Shabdar Ghata": Pin
rajeshvarikkol16-Mar-11 2:47
Memberrajeshvarikkol16-Mar-11 2:47 
GeneralMy vote of 5 Pin
raphu27-Nov-10 1:27
Memberraphu27-Nov-10 1:27 
GeneralMy vote of 5 Pin
enesiii21-Jul-10 4:12
Memberenesiii21-Jul-10 4:12 
GeneralRe: My vote of 5 Pin
raphu27-Nov-10 1:29
Memberraphu27-Nov-10 1:29 
GeneralNot Working in Windows 7 Pin
Anto George2-Jul-10 17:01
MemberAnto George2-Jul-10 17:01 
GeneralRe: Not Working in Windows 7 Pin
zylaoer23-Jul-10 23:51
Memberzylaoer23-Jul-10 23:51 
GeneralExporting data does not work Pin
Member 3081795-May-10 12:41
MemberMember 3081795-May-10 12:41 
GeneralForeign Key Constraints Pin
Member 6058853-Nov-09 7:37
MemberMember 6058853-Nov-09 7:37 
QuestionRestore location Pin
Gitosh22-Sep-09 4:34
MemberGitosh22-Sep-09 4:34 
GeneralThe system cannot find the file specified Pin
svknair25-Jul-09 2:26
Membersvknair25-Jul-09 2:26 
Questionhow to use this application for windows authentication. Pin
abhi4wit4-Jul-09 3:10
Memberabhi4wit4-Jul-09 3:10 
GeneralTry EZmanage SQL Pro for better mssql backup Pin
itayl27-May-09 3:08
Memberitayl27-May-09 3:08 
GeneralC# Version Pin
sivaprasad@198423-Apr-09 18:16
Membersivaprasad@198423-Apr-09 18:16 
GeneralSQLDMO not found Pin
skhurams18-Apr-09 11:05
Memberskhurams18-Apr-09 11:05 
GeneralCongratulations Pin
m.conta27-Nov-08 3:01
Memberm.conta27-Nov-08 3:01 
Questionvarchar (max)? Pin
murali_utr12-May-08 19:51
Membermurali_utr12-May-08 19:51 
AnswerRe: varchar (max)? Pin
Redi Linxa29-May-10 5:35
MemberRedi Linxa29-May-10 5:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 22 Nov 2007


142 bookmarked