![]() |
Platforms, Frameworks & Libraries »
.NET Framework »
Utilities
Advanced
License: The Code Project Open License (CPOL)
SQL Server Database Backup Utility using VB.NET and SQL-DMO (New version)By Shabdar GhataA Windows application to backup and restore SQL server tables,views,user defined functions and stored procedures |
VB, SQL, .NET (.NET2.0), Win2K, WinXP, Win2003, Vista, SQL-Server (SQL2000, SQL2005, SQL-CE), ADO, ADO.NET, VS2005, DBA, Dev, QA
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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:
I will be doing more updates to this program in the next few days. Please check my Website, shabdar.org, 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.
To backup the database,
Adv_StackedBar2 and Adv_UserRoleTypes tables will be excluded from backup. UserID > 10 and UserID < 25 in the above picture. It means only those records will be exported which satisfy this condition. Top 20 *, means only top 20 rows will be exported for Adv_TodaysOutlook table. To restore the backup,
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.
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.
'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()
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.
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.
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.
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Mar 2008 Editor: Deeksha Shenoy |
Copyright 2007 by Shabdar Ghata Everything else Copyright © CodeProject, 1999-2010 Web22 | Advertise on the Code Project |