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
|
GeoffS Level: VB Lord Registered: 29-09-2004 Posts: 536
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
|
yronium Level: Moderator Registered: 14-04-2002 Posts: 907
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
|
JLRodgers Level: Moderator Registered: 04-04-2002 Posts: 1616
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)