Click here to Skip to main content
Click here to Skip to main content

SQL Server backup utility

, 3 Jun 2006
Rate this:
Please Sign up or sign in to vote.
Restore/backup selected objects in SQL Server.


Whenever we want to backup or move SQL Server databases, most of us prefer to use a regular backup utility which is available through the Enterprise Manager in SQL Server 2000 or the Management Studio available in SQL Server 2005. The limitation of using the Enterprise Manager or the Management Studio is 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 the backup of only 15 tables out of 100 tables. I want to backup only a few records from these selected tables. For that reason, I was looking for a small utility which allows me ht facility. After searching through hundreds of utility programs, I decided to write my own.


  • Backup of selected objects
  • Backup of selected data
  • Can backup scripts alone
  • Can backup data alone

Using the program

To backup the database:

  • Open the database backup window from the Tools menu.
  • Enter the server name, database name, user name, and password for SQL Server.
  • Click on Connect. This will display all the available tables, views, stored procedures, user defined functions, user defined datatypes, and users from the database.
  • Select how many rows you want to export from each table, e.g., 'Top 1000 *'. Default is 'Top 100 percent', which means all rows.
  • If you want to backup data alone, check Backup Data and remove the checkmark from Backup object structures (Scripts).
  • If you want to backup scripts alone, check Backup object structures (Scripts) and remove the checkmark from Backup Data.
  • Select objects that you want to backup from the list. By default, all objects are selected.
  • Apply any condition on the table data. For example, 'StudentID > 120 and StudentID < 200' in the above picture. It means only those records will be exported which satisfy this condition.
  • Modify the number of rows to export on a particular 'table', if you want to do so. For example, in the above picture, 'Top 99 *' means top 99 rows only for the 'OtherIncome' table.
  • Click on Start Backup. It will ask you to enter a file name and location. Note that the backup file has an extension *.SQLBackup.

To restore the backup:

  • Open the Database Restore window from the Tools menu.

  • Enter the server name, database name, user name, and the password for SQL Server.
  • Select the database backup file that you want to restore. Note that the database backup file extension for this program is *.SQLBackup.
  • When you select the backup file, it displays all the objects available in the backup.
  • If you want to create a new database, check the Create New Database option.
  • If you want to drop existing an database and recreate it, check both the Create New Database and the Drop Existing Database options.
  • Select the objects that you want to restore from the list. By default, all objects are selected.
  • Click on Start Restore.

Using other features

  • As you can see on both the backup and the restore forms, there are buttons available as Load Settings and Save Settings As. Once we setup different parameters for backup, i.e., selecting objects, specifying conditions etc., we can save all of these together in a settings file. We can load these settings any time we want, so that we do not need to enter those conditions each and every time we restore or backup a database.

Using the code

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

Objects from the 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 a 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 can not take backups of user roles and triggers.
  • The backup file (*.SQLBackup) format is a Zip format. It can not be restored using Enterprise Manager. (If you rename this file to *.zip, you can extract it using WinZip or other Zip utilities and view its contents.)


  • Multi-threading can be added during the backup or the restore process. This will avoid freezing of forms, specially during the backup or restore process of large databases.
  • 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 used for your regular backups.


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


  • Visual Studio .NET 2005 (for the source code)
  • .NET Framework 2.0
  • MS SQL Server 2000, or MS SQL Express 2005, or MS SQL Server 2005 client components (for the SQL-DMO Library)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Shabdar Ghata
Web Developer
Canada Canada
Software Developer

Comments and Discussions

QuestionBackup PinmemberSaark Computers23-Jan-15 20:17 
Generalhi Pinmembersajjiamo9-Mar-11 20:01 
Generalhelp-help Pinmemberaseman_shab31-Dec-10 21:56 
GeneralKeep it up Shabdar PinmemberSayed Sajid31-Jan-10 3:21 
GeneralPerfect! Pinmemberreachen27-Sep-09 20:21 
GeneralThanks for sharing this! Pinmemberreachen18-Aug-09 7:23 
Generali am using EZManage SQL Pro to backup my sql servers Pinmemberitayl27-May-09 4:09 
GeneralThanks a bunch! Pinmemberjm007727-Feb-09 10:28 
QuestionError when i Restore data PinmemberMember 147151713-Feb-09 9:07 
GeneralGreat article, take a look at that tool also. Pinmemberroby548-Nov-08 12:03 
JokeCongratulations Pinmemberrolandocamachorojas1-Aug-08 12:57 
GeneralError while taking back up from Backup Utility Pinmemberershad24-Jun-08 5:24 
GeneralRe: Error while taking back up from Backup Utility Pinmemberczekanm20-Jan-11 3:19 
GeneralBrilliant! Pinmembertoddwprice3-Jun-08 11:40 
GeneralDoesn't work with Vista... PinmemberYogiman14-Mar-08 8:01 
NewsNew version of this utility is available PinmemberShabdar Ghata22-Nov-07 12:10 
GeneralRestore is empty Pinmemberocram111-Oct-07 11:24 
AnswerRe: Restore is empty PinmemberShabdar Ghata11-Oct-07 12:22 
GeneralRe: Restore is empty Pinmemberocram112-Oct-07 12:48 
GeneralWithout sqldmo library Pinmemberzawmn8319-Sep-07 22:12 
Questionproblem in inserting row Pinmembergaurav kumar jaiswal26-Aug-07 23:28 
AnswerRe: problem in inserting row Pinmembermajid_vb28-Oct-07 12:34 
Generallogin form Pinmemberzaqxsws321020-Aug-07 18:06 
Generalek!!plzz Pinmemberm.rizal20-Aug-07 17:48 
QuestionUnKnownError Pinmemberanahita_m27-May-07 1:25 
AnswerRe: UnKnownError Pinmemberershad21-Jun-08 9:18 
Generalcannot connect ErrorProviderExtended1 Pinmemberryan12143-Apr-07 4:53 
GeneralForeign_keys problem Pinmembereugenia5429-Dec-06 13:50 
Generaloutofmemoryexception Pinmembereugenia5420-Dec-06 11:31 
Generalexception of type system.outofmemoryexception was thrown Pinmemberzerdust_reso14-Dec-06 4:05 
Generalto compare database Pinmemberba9801812-Dec-06 10:41 
GeneralRe: to compare database PinmemberShabdar Ghata12-Dec-06 12:24 
QuestionCan u modifiy this code into 2002? Pinmemberryan G15-Sep-06 22:44 
QuestionIs possible works with SQL Express File attach? PinmemberPakT10-Aug-06 2:26 
Questionhow did you achiece backup database in another machine to localhost? Pinmemberedisom11cao27-Jul-06 21:00 
AnswerRe: how did you achiece backup database in another machine to localhost? [modified] PinmemberShabdar Ghata29-Jul-06 8:11 
GeneralUnable to logon Database Pinmembertrchoudhry19-Jul-06 12:39 
GeneralRe: Unable to logon Database PinmemberShabdar Ghata29-Jul-06 8:15 
Generalerror PinmemberAlonZanbar8-Jun-06 23:43 
GeneralRe: error PinmemberShabdar Ghata29-Jul-06 8:17 
GeneralRe: error PinmemberwingerCP26-Aug-06 8:27 
GeneralRe: error Pinmemberyusuf_ceng17-Dec-06 9:01 
Questionimage or blob Pinmembercomeltan4-Jun-06 23:23 
AnswerRe: image or blob [modified] PinmemberShabdar Ghata6-Jun-06 17:31 
QuestionSource code works? Pinmember| Muhammad Waqas Butt |4-Jun-06 0:22 
AnswerRe: Source code works? PinmemberShabdar Ghata4-Jun-06 6:53 
QuestionRe: Source code works? PinmemberButt 4 .Net6-Jun-06 2:29 
AnswerRe: Source code works? [modified] PinmemberShabdar Ghata6-Jun-06 17:17 
GeneralSource code updated to include project file PinmemberShabdar Ghata3-Jun-06 17:33 
GeneralProblem Pinmemberothello12008-May-06 22:18 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150301.1 | Last Updated 3 Jun 2006
Article Copyright 2006 by Shabdar Ghata
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid