Whenever we want to backup or move SQL Server database, most of us prefer to use regular backup utility which is available through Enterprise Manager in SQL Server 2000 or Management Studio in SQL Server 2005. Limitation of using Enterprise Manager or 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 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.
Release (1.1.1) July 2011
Added a small fix for table names with spaces.
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. Here is a list of changes I have made in this program.
-
Backup file extension is now .ZIP instead of .SQLBackup. This is to avoid any confusion.
-
Old version was having 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 program won’t freeze during long operations.
-
UI is improved to display proper status of backup and restore.
-
Included GNU license.
Download Source (945KB) (new version July 13, 2011)
Download Setup (2MB) (old version)
Features
-
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
To backup database,
-
Open 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 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 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 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. Remeber 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 backup,
-
Open Database restore window from tools menu.
-
Enter server name, database name, user name and password for SQL Server.
-
Select database backup file(*.zip) that you want to restore. Remeber this utility can only restore those backup files(*.zip) which are created by this utility itself. It can not restore regular sql server backup file.
-
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 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
Using Code
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
objBCP.DataFilePath = "c:\temp\EmployeeData.dat"
db.Tables.Item("Employee").ExportData(objBCP)
'Generate script with drop statement
Dim SQL as String =
db.GetObjectByName("Employee").Script(SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops)
+ db.GetObjectByName("Employee").Script()
Limitations
Enhancements
Acknowledgments
Requirements
.Net Framework 2.0
MS SQL Server 2000 or MS SQL Express 2005 or MS 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. You can download it from following link,
Download Microsoft SQL Server 2005 Backward Compatibility Components
These components are needed for SQL-DMO library -
Download setup zip file from link provided on top of this article. Extrace and run setup.exe. It should create icons in your programs menu and desktop
How to use source code
-
Download source code zip file from link provided on top of this article and run DatabaseBackup.sln solution file with Visual Studio 2008.
Special Notes
I have published this article on codeproject.com as well. Here is the link to this article.
http://www.codeproject.com/vb/net/SQLDBBackup.asp
Comments/Questions
Doesn’t work with vista.
It gives error saying it has stopped working as soon as I hit backup. It connects fine to the server and displays tables and other objects but cant backup. => sunny (Friday 14-Mar-08 11:39 AM)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Thanks for the great work. Problem however; I’m backing up from SQL Server 2005 Express, user table data only, that works fine.
But when I open the zip file to restore, no objects (table names I assume) appear in the Tables tab below. Nothing appears there at all. Is this a known bug with a fix? Running Windows XP SP2, SQL 2005 Express SP2 SSMS. Cheers! => Andrew (Tuesday 25-Mar-08 08:04 AM)
Great program, but I wonder if in a future version it will manage schema, i mean make a back up of a schema, or filter the tables by schema?
=> Daniel Brito (Thursday 10-Apr-08 12:20 PM)
From what I have researched so far sounds like a great program! 2 questions though. 1) Is the database actually compressed?
2) Could I use this program with the task scheduler to backup every night? Basically write a batch file that starts the program executes and closes. Thanks much => Mike (Sunday 13-Apr-08 11:12 PM)
Sometimes I get error while backing up tables and program shutdown intermittently.
I backed up the Data and object structure in 2 different file and that worked Excellent, program to back the SQL Server. => Sarfaraz (Monday 14-Apr-08 08:24 AM)
Hi
Great prog. But it doesn’t work when a table is into a schema. like mike.table1 (not dbo.table1). => mike (Wednesday 30-Apr-08 03:52 AM)
Mister, can I use with integrated authentication ? thanks in advance
=> ae (Wednesday 30-Apr-08 09:29 AM)
Mister, why use OleDb Connection, not Sql Server Connection? any reason about it ? thanks.
=> ae (Wednesday 30-Apr-08 10:02 AM)
Whenever i am trying to take backup i click on connect button, it connects and shows all table of database but not taking
backup sometime it show this error “Could not find file ‘D:Documents and SettingsAdministratorDesktopDatabaseBackupbinDebugBackupTempAccessories.dat’.” => Ershad Ali (Saturday 21-Jun-08 05:28 AM)
after clicking on connect button showing all tables, but when trying to take backup by click on back button it shows sometime this error also
“[Microsoft][ODBC SQL Server Driver][SQL Server]Code page 720 is not supported by SQL Server [Microsoft][ODBC SQL Server Driver]Unable to resolve column level collations” => Ershad Ali (Saturday 21-Jun-08 05:33 AM)
Hi
please give me solution for my problem which i mention earlier => ershad ali (Monday 23-Jun-08 09:58 AM)
is there a way to compare the script prepared by the objects and come with a change in any objects by keeping a source and destination server. Something like a database sync utility.
=> AK (Wednesday 25-Jun-08 03:45 PM)
when i restore database form local machine to remote server that time my table name is change with dbo,means my table name is citymaster then it display on server usrname.citymaster and this give error when i run my application what is solution
=> Amit (Saturday 05-Jul-08 04:50 AM)
Wanted to know what this error was.
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 38: Length or precision specification 0 is invalid. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name ‘[tableName]’. It happens only on 1 of my tables, but when ive done other databases and tried to restore same problem. => Dk (Friday 18-Jul-08 02:01 AM)
How Can I work with windows authentication database (itegerated security)
the backup utility doesn’t work on this case => Nisreen (Sunday 27-Jul-08 03:15 AM)
the program make the backup and restore but only the structure no the data, how can backup all the record for each table ?
=> roberto (Friday 01-Aug-08 10:41 AM)
i found a problem when restoring a database with tables linked by foreign key , where when adding the table it adds all its relation regardless that the related table has not beeen created yet.
=> walid (Sunday 03-Aug-08 02:19 AM)
hi
i was use the source in sql database project with vb2005, when i use the backup and restore form, a message box appear that (Check Parameters, SQL server does not exists or invalid user name and password given . check Server name or password and username) => mc (Saturday 09-Aug-08 12:05 AM)
After i was clicking on The connect button showing all tables, but when i’m trying to get backup by click on backup button, i have this error “[Microsoft][ODBC SQL Server Driver][SQL Server]Code page 720 is not supported by SQL Server
[Microsoft][ODBC SQL Server Driver]Unable to resolve column level collations” => mc (Saturday 13-Sep-08 12:59 AM)
well, when i start debugging the code source, and after clicking Start Backup, the compiler stop on this code:
“db.Tables.Item(sTableName).ExportData(objBCPExport)” in the ‘ExportData’ function in ‘clsScript’ Class. did u have any solution, => mc (Saturday 13-Sep-08 01:09 AM)
Thanks for this Backup Utility!!! I translated it to Spanish so if you want it just ask… thanks again…
=> Jorge Villacorta (Thursday 18-Sep-08 11:33 PM)
Hai Shabdar,
Thanks for apps, I’m already try to used your apps on win2k3 sp2 server, but when try to backup using condition, i found that the apps just stop/close without notification, and on event viewer i’m find somthing like this: Event Type: Error For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp. How can resolved this problem? Many Thanks Triesna => triesna (Wednesday 29-Oct-08 03:02 AM)
Thanks for the program.
it keeps on crushing when trying to backup a remote DB. am using win xp pro with sql server 2005 installed. here is what i was able to collect: EventType : clr20r3 P1 : databasebackup.exe P2 : 1.0.0.0 —– An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in DatabaseBackup.exe Additional information: [Microsoft][ODBC SQL Server Driver][SQL Server]Code page 862 is not supported by SQL Server => ziv (Monday 17-Nov-08 04:58 AM)
Hi
i am restoring sql server 2005 express database to sql server 2000 database using above Utility. one column is in binary format in sql server 2005 express databse. Are athere any sugesstions Bye => chandra sekhar (Wednesday 10-Dec-08 09:36 AM)
|
{kunena_discuss:17}