Access DB Backup From A Form?

  • Thread starter Thread starter Webbyz
  • Start date Start date
W

Webbyz

I have a code question. I am trying to figure out how to make a backup
of a .mdb database when a user selects the "BackUp Database" option
from the MainManu Control I have created. I would like the application
to take the current database file 'WASA.mdb' and copy it into another
folder.

My current folder that is holding the database is C:\Program
Files\WASA\BIN\

So the current path to my DB is C:\Program Files\WASA\BIN\WASA.mdb

I would like to copy this instance of the database on the users command
to another folder.

This folder will be C:\Program Files\WASA\BIN\BACKUP\

I cannot find a way to do this function. If anyone has any suggestions
please let me know. Thanks a bunch.
 
All you have to do is:

Imports System.IO

Dim strDB As String = Application.StartupPath & "\wasa.mdb"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If BackUpDB(strDB, "C:\wasa.mdb", True) = True Then ' True =
Overwrite previous if exists
MessageBox.Show("Successful", Me.Text, MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("Unsuccessful", Me.Text, MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If
End Sub

Private Function BackUpDB(ByVal sFrom As String, ByVal sTo As String,
Optional ByVal bOverwrite As Boolean = False) As Boolean
Try
File.Copy(sFrom, sTo, bOverwrite)
Return True
Catch ex As IO.IOException
'MessageBox.Show("File already exists", "Backup Database",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Catch exx As Exception
'MessageBox.Show(exx.Message, "Backup Database",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
 
Try

Imports System.IO

[Within Sub/Function]

File.Copy(sourcefile[string],destinationfile[string],[boolean])

HTH, Phil
 
Awsome! Works like a charm! Thanks Crouchie!
Also thanks Phil but I did not try your solution since Crouchies worked
but thanks again.
Crouchie.....if you ever want to make some money....let me know. I am a
college kid with a Senior Project and you are awesome!
 
Hey Crouchie or anyone else. Now that I have the file saving with a
date and a time on it...if I want to make a restore database function
on a button click how would I go about reading the selected file and
renaming it to the same file name my program is calling. Here is my
example.

Button Name: btnRestore

File Name after Backup: 9-27-2005,1210PM.mdb (Note This is the date
and time of save )

File Name Program Refers To: wasa.mdb

I just need an Open File Dialog that once the person selects the back
up database 9-27-2005,1210PM.mdb that it will take that file and put
it into the /bin folder where my database is being called and rename
it wasa.mdb

Any help would be apperciated. Thanks a bunch.
 
Hello Again!!

Sorry for not getting back to you for a while, but I have my own work to do.

In order for you to restore the database you will need to log the user(s)
out firstly, copy the file (renaming it) & then log the user back in

If you don't do this then you won't be able to copy the database across
because of the 'lock' file (if not running in disconnected mode) & you'd
always be looking at the original data, rather than the restored version.

How many people will be accessing the database at once? You will need to
notify the other users (if more than one) that you are restoring the
database (if not running in disconnected mode) & then log yourself out, copy
the database across, log back in & then allow the other connections. Does
that make sense?

Also, will the restore be a 'copy' or a 'move' of the restored database?
Will this function need access rights? Example: Only DB Admins can copy the
database or domain/workstation Admins or everyone? This has to do with
setting up the copy rights with security etc.

Please let me (us) know the answer to the above.

Finally, sorry for not getting back to you straight away.

Crouchie1998
BA (HONS) MCP MCSE
 
This is actually a stand alone application. It will only be run on one
workstation. No more than one person would access it at a time. The
restore will be a move. And access will be allowed to all of those with
any access to the program. And also, if you could. Is there an easy way
to link Passwords and Usernames to the DB? I am using a static call to
the code which is not the best way at all. Just curious. Also, if you
would like a copy of the code itself....let me know. Thanks a bunch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top