Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Backup MS Access Database?

283 views
Skip to first unread message

Prabhat

unread,
May 23, 2007, 9:52:22 AM5/23/07
to
Hi Friends,

My Application is connected to MS Access database. I want to provide one
option as Backup and another option for Restore. I use Delphi 5 with ADO to
connect DB.

What is the best way to Backup the Dabase and Restore it?

I think as this is a Filebased DB, We should Make a Copy of the Database
file (.mdb) and Compact the new copied file.

Please suggest any idea. If i can get some Code fragment it will be helpful
for me.

Thanks
Prabhat
http://prabhatnath.blogspot.com


Stuart Bloom

unread,
May 23, 2007, 10:44:53 AM5/23/07
to
Here is a method i use when compacting an ADO dataset and also has the
ability of backing it up.

procedure TdmData.CompactAndRepairDatabase(AInput, AOutput: string;
BackUp: Boolean = False);
const
sConString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
var
oJetEng: JetEngine;
begin
adocData.Close;

if FileExists(AOutput) then
DeleteFile(PChar(AOutput));

oJetEng:= CoJetEngine.Create;
try
try
oJetEng.CompactDatabase(sConString + AInput, sConString + AOutput);
if not BackUp then
begin
DeleteFile(PChar(AInput));
RenameFile(AOutput, AInput);
end;
except
on E:Exception do
ShowMessage(E.Message);
end;
finally
oJetEng := nil;
end;

adocData.Open;
end;

Hope it helps.

Stu

Prabhat

unread,
May 23, 2007, 11:14:09 AM5/23/07
to
Hi Stuart,

Thanks for the sample code. Can you please let me know what are the units
that i need to include in "uses" section? I think JRO_TLB will do the work.

Also in your case what is "adocData"? Is that the Connection?

Thanks Again
Prabhat Nath
http://prabhatnath.blogspot.com


"Stuart Bloom" <stu...@thebloomfamily.co.uk> wrote in message
news:4654...@newsgroups.borland.com...

Stuart Bloom

unread,
May 23, 2007, 1:10:28 PM5/23/07
to
Prabhat

You need to include JRO_TLB (as you correctly found ount). adocData is
TADOConnection.

Hope this helps.

Prabhat

unread,
May 24, 2007, 4:18:02 AM5/24/07
to
Hi Stuart,

Thanks for the info. Yes it is very useful for me. Thanks.

Prabhat
http://prabhatnath.blogspot.com

DRS

unread,
May 31, 2007, 8:14:16 AM5/31/07
to
"Prabhat" <not_a...@hotmail.com> wrote in message
news:46554a3b$1...@newsgroups.borland.com

> Hi Stuart,
>
> Thanks for the info. Yes it is very useful for me. Thanks.

You may also like to look at http://cc.codegear.com/Item/15256. BTW, please
don't top post.


kbbo...@gmail.com

unread,
Feb 2, 2017, 8:27:43 AM2/2/17
to
So what do I need to change in this code to backup and what code to restore. I have critical database that I must not damage trying to code backup.

thanks!!!
0 new messages