borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (have some problem when showing item from database to listbox)Next Topic (Data Shaping Problem) New Topic New Poll Post Reply
AndreaVB Forum : Database : BACK UP AND RESTORE DATABASE
Poster Message
ashiyr
Level: Protégé

Registered: 05-04-2007
Posts: 5

icon BACK UP AND RESTORE DATABASE

hi,
i'd like to ask if somebody here in ANDREAVB know how to backup and restore database, im using VB6 and MSACCESS. i want to back up my MSACCESS and restore it when i click the button restore and restore it when the program open. is there any code for this? kindly help...

05-04-2007 at 04:03 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon Re: BACK UP AND RESTORE DATABASE

Hi,
The easiest way is to copy the Database File to your backup location, then to restore you would copy it back in place of the existing file. Use "FileCopy Source, Destination"

FileCopy "C:\MyData.mdb", "D:\MyBackup.mdb"

'To restore remove the existing and then copy backup
Kill "C:\MyData.mdb"
FileCopy "D:\MyBackup.mdb", "C:\MyData.mdb"



____________________________
multi-tasking - the ability to hang more than one app. at the same time.

07-04-2007 at 08:39 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: BACK UP AND RESTORE DATABASE

Hello. I agree to Geoffs up to a little point: instead than killing at once the old file, I'd try to rename it by the Name function. This function returns a catchable error if the file is open, so you can know if the .mdb is in use by somebody else before killing it. If you get no errors after renaming it, you can create the copy and then kill the renamed original file. Otherwise, you can suggest user to try again later by a messagebox. See Help for details on the Name function.
Of course, since you use MSAccess, you can simply create a bare copy of the .mdb, but if you plan to upgrade to another engine in the future you should consider using the specific dbms' backup and restore features. Time ago, I wrote an article about backing up an SQLServer/MSDE db, you can find it here.
Hope it helps.

____________________________
Real Programmer can count up to 1024 on his fingers

07-04-2007 at 12:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: BACK UP AND RESTORE DATABASE

Copying the database file itself is the easiest way to do it.

The only other way would be to do it all manually (i.e. create a new database with code, create all the tables in code, make select/insert SQL statements to insert code from the one to the other).  Then you'd have to reverse the process to an extent to restore.

Copying the file can be as simple as three lines of code (as you were already provided).

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

07-04-2007 at 03:26 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Database : BACK UP AND RESTORE DATABASE
Previous Topic (have some problem when showing item from database to listbox)Next Topic (Data Shaping Problem) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder