Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - Simple Backup/Restore Utility With SQL-DMO...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Simple Backup/Restore Utility With SQL-DMO Using VB.NET
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 55
    2005-09-08

    Table of Contents:
  • Simple Backup/Restore Utility With SQL-DMO Using VB.NET
  • Understanding SQL-DMO Objects
  • Programming SQL-DMO using .NET
  • Backup/Restore utility using SQL-DMO with .NET
  • Understanding Backup and Restore processes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Simple Backup/Restore Utility With SQL-DMO Using VB.NET - Understanding Backup and Restore processes


    (Page 5 of 5 )

    The following is the code to work with the Backup process using SQL-DMO:

    Private Sub doBackup()

            With oBackup

                '.Devices = "[NorthwindBackup]"

                .Files = _BACKUPFILE

                .Database = _DATABASE

                .BackupSetName = "MyNorthwindBkp"

                .BackupSetDescription = "Backup from VB.NET application"

                oSQLServer.Connect(_INSTANCE, _USER, _PWD)

                .SQLBackup(oSQLServer)

            End With

            MessageBox.Show("Backup Completed Sucessfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End Sub

    I hope the steps are very simple.  Specify the Backup file name, database name, backup set name, and some description. Connect using oSQLServer object; take the backup using the SQLBackup method of oBackup object by using the connection at oSQLServer object.

    Similarly, we can have the code for Restore process as follows:

    Private Sub doRestore()

            With oRestore

                '.Devices = "[NorthwindBackup]"

                .Files = _BACKUPFILE

                .Database = _DATABASE

                .ReplaceDatabase = True

                oSQLServer.Connect(_INSTANCE, _USER, _PWD)

                .SQLRestore(oSQLServer)

            End With

            MessageBox.Show("Restore Completed Successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End Sub

    NOTE: Make sure you close the SQL Server Enterprise Manager before operating the Restore process, as it maintains an exclusive connection to the database.  If you drop the existing database and try to restore it, you have no need to close it.

    Remarks: The entire source code of this article exists in the form of zip downloadable (which includes the SQL-DMO object tree GIF).  I developed this small tool using Microsoft SQL Server 2000 Enterprise Edition and Visual Studio.NET 2003 Enterprise Architect.  It may also work with other SQL Server versions prior to MS SQL Server 2000, but don’t hesitate to drop in if the tool doesn’t work with other versions (basically I didn’t test it on other versions).  As SQL-DMO is a COM component, you can also use it with Visual Basic 6.0 (but with very slight syntactical changes from the above code).  You can also develop web based database administration tools using classic ASP or ASP.NET with SQL-DMO.

    I leave it to the programmers for further enhancements.  Any doubts, comments, suggestions, bugs, errors or feedback are welcomed at jag_chat@yahoo.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys, this is my article on SQL-DMO together with VB.NET. You can start...
       · Tried to download the file for the article but the link doesn't seem to...
       · Hello, I fixed that link. Thank you for pointing it out to us :-)Mike
       · backup code is working perfectly , but the restor code is not working its giving...
       · please follow the "note" section of the article. Try to close Enterprise manager...
       · Dear Jagdish,This is a wonderful article! Can you kindly help for a similar kind...
       · Hai, thanks for your compliments. And thanks again for requesting me on...
       · Hi jagdish Have u released the article about replication which was asked by...
       · Hi JagdishNice article, but I am connecting to sql server using windows...
       · Hi Sita, This is palash. I have faced a similar problem like you. Did you find any...
       · DEAR SIR I IMPLEMENTED THT CODE BUT ITS NOT WORKING ,SO PLS SEND ME RELAVT CODE or...
       · Hi There,My Backup and restore code works fine but I have one problem.It...
       · This is wonderful artical.Can u help me to take the backuo of selected table(not...
       · This helps:oSQLServer.LoginSecure = true; oSQLServer.Connect("ServerName",...
       · Hi, Thanks for such a simple and useful utility. It is really cool. it works...
       · Can anyone help me with this problem?I want to restore selected backup which can...
       · The restore cannot be done if the database is being used. So if the datagrid uses...
       · This article is simply perfect! Short, Clear and concise. Thanks a lot..For...
       · Hi Sita and PalashI am Kulwinder Singh. I found out the solution for ur...
       · where is the link? i cant download the file.. please help me.
       · I am Rohit, I am using VB.Net. I am Beginner in .Net VS 2005. I want to know how...
       · can you give me the link to download this program
       · i am jerry can you give me link to download this program:)) thank
       · Hey Thanks For The code....!!Bi!
       · Hello.. i have got an error like "type SQLDMO.SQLServer is not defined" now what to...
       · Hello Mr. chaterjee and all friends,This article is great ! I m new to back up...
       · Have you got the solution for this please reply me
       · Hi Jagdish....It really fullfilled my needs... Thank youRegardsSTEEL
       · hi, Friendsi have a problem for restore the data using...
       · Public Class Form1 Dim osqlserver As New SQLDMO.SQLServer Dim WithEvents...
       · i want to use this code but it gives error in these line Dim osqlserver As New...
       · Hi,Im trying to do the restore after doing the backup and I got the following...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT