20/12/2011

How to take backup from a database? Vb.net computer programming code for beginners

Taking backup from a database  in data management system is very important as the data which we are generating in our daily use of a software is required to be safely backed up to avoid loss of data due to break down of computer by any reasons, like virus attack, or software/ hardware breakdown.For better understanding of these type of vb.net code or database related inquiry the book written by Donald E Knuth Bible of Computer programming is very great book which is available on amazon with free shipping charge, I will suggest one can  refer

Therefore creating a tool for database backup is very important to retrieve data from database and keep it in a save place so same can be use if database get corrupted . There are lots of  free data back up solutions are available but this back up code which I have incorporated in  my main software is quite simple can be incorporated while developing a software creating a suitable event . The Vb.net code which I have used here is  on the click event of BackupToolstrip_ menuitems of Main form in which I also tried to show the detail regarding the date and time when the back up was taken by creating a log file.

Try
 Dim s As StreamWriter
Dim portfolioPath As String = My.Application.Info.DirectoryPath
If Not Directory.Exists("C:\Backup") Then
Directory.CreateDirectory("C:\Backup")
File.Create("C:\ Backup\PIS.Mdb").Close()
File.Create("C: \Backup\Backup log.rtf").Close()" this for making of log about when the back was taken last
s = New StreamWriter("C:\Backup\Backup log.rtf", True)
s.WriteLine("This backup was initially taken on - " & Date.Now)
                s.Flush()
                s.Close()
FileCopy(portfolioPath & "\PIS.mdb", "C:\Backup\PIS.Mdb")
s = New StreamWriter("C:\Backup\Backup log.rtf", True)
 MsgBox("New directory and backup file created")
            Else
'Creating a directory by specifying a path in the TextBox, of the form c:\examples
'Instead of using a TextBox you can directly type the location of the directory like this
                'Directory.CreateDirectory("c:\examples")
FileCopy(portfolioPath & "\PIS.mdb", "C:\Backup\PIS.Mdb")
s = New StreamWriter("C:\Backup\Backup log.rtf", True)
s.WriteLine("This backup was latest updated on - " & Date.Now)
                s.Flush()
                s.Close()
MsgBox("Back up completed successfully")
            End If

        Catch ex As Exception
Dim MessageString As String = "Report this error to the system administrator: " & ControlChars.NewLine & ex.Message
      Dim TitleString As String = "Employee Master Details Data Load Failed"
       MessageBox.Show(MessageString, TitleString, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
 In the above mentioned code the the backed up database will be generated on  the C root drive Directory  name "Backup" and Database name "PIS.Mdb" . The database name should be same which is in used in your software.and The log file name "Backup log .rtf" will also be generated in the same directory which will provide the detail regarding the date and time of the backup was taken so this log will help to tell, how old the back up is ?

If you want to master yourself in computer programming please go through the review of Computer Book

Art of Computer Programming, Volume 1: Fundamental Algorithms (3rd Edition) [Hardcover] By  Donald E Knuth

Review by some programmers

 Anyone who aspires to be a transcendent programmer must own (and use) Knuth. I've used my 20 year old TAOCP vol. 1 so many times over the years that it lays flat at any page.
The updated volume 1 is more of the same - a classic revisited, revamped, restored. It is odd to handle something so familiar, yet so crisp.
Those who dislike MIX will be unimpressed - to them, I say that you don't learn by doing the same vanilla thing time and again, but rather by wrestling with unfamiliar concepts and architectures. Many times my fellow programmers will find themselves roadblocked in an unfamiliar situation, while I often can see the unobvious solution - I attribute this ability to a wide experience with unconventional solutions, including extensive study of Knuth's TAOCP.
If you're serious about your programming abilities, you *must* own (and study) this book! Frankly, if computer science were taught as an apprenticeship, this would be the journeyman's manual. I've required the many programmers I've trained over the years to own and study TAOCP, and they've all come to appreciate it's layered approach to problems - you can read Knuth at many levels, from algorithm reference to meta-analysis of an entire class of problems.
If there is a Koran, Bible, or Tao of Computer Science, this is it. The only thing close is Aho's "Dragon Book," and it's specific to compilers.


You also like this, How to restore the data in database? VB.Net code