Board index » delphi » How to compact access database with database password ?

How to compact access database with database password ?

Hi,
 I use this to compact my database

function CompactAndRepair(sOldMDB : String; sNewMDB : String) : Boolean;

const sProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;Password="";';
var oJetEng   : JetEngine;
begin
  sOldMDB := sProvider + 'Data Source=' + sOldMDB;
  sNewMDB := sProvider + 'Data Source=' + sNewMDB;

  try
     oJetEng := CoJetEngine.Create;
     oJetEng.CompactDatabase(sOldMDB, sNewMDB);
     oJetEng := Nil;
     Result  := True;
  except
     oJetEng := Nil;
     Result  := False;
  end;
end;

but when I set the database password, this procedure won't work, even
after I
replace this line:

sOldMDB := sProvider + 'Data Source=' + sOldMDB+'Jet OLEDB:Database
Password=xxx';
sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:Database
Password=xxx';

please help.
Thanks

 

Re:How to compact access database with database password ?


Hi Denny,

Quote
> but when I set the database password, this procedure won't work, even
> after I replace this line:
> sOldMDB := sProvider + 'Data Source=' + sOldMDB+'Jet OLEDB:Database
> Password=xxx';
> sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:Database
> Password=xxx';

Did you try:
sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:New Database
Password=xxx';

Thrse

Re:How to compact access database with database password ?


Quote
"Thrse Hanquet" wrote:
> Hi Denny,

> > but when I set the database password, this procedure won't work, even
> > after I replace this line:
> > sOldMDB := sProvider + 'Data Source=' + sOldMDB+'Jet OLEDB:Database
> > Password=xxx';
> > sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:Database
> > Password=xxx';

> Did you try:
> sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:New Database
> Password=xxx';

> Thrse

Yes, it doesn't work either.....
Thanks

Re:How to compact access database with database password ?


Hi Denny,

Quote
> > Did you try:
> > sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:New Database
> > Password=xxx';

> Yes, it doesn't work either.....

Well there is something else that can cause the problem: how do you provide the
required ';' separator between sOldMDB or sNewMDB and "Jet OLEDB:"?

Thrse

Re:How to compact access database with database password ?


Thank you, it works fine !!!
you're right about the ';' :)

Thanks

Quote
"Thrse Hanquet" wrote:
> Hi Denny,

> > > Did you try:
> > > sNewMDB := sProvider + 'Data Source=' + sNewMDB+'Jet OLEDB:New Database
> > > Password=xxx';

> > Yes, it doesn't work either.....

> Well there is something else that can cause the problem: how do you provide the
> required ';' separator between sOldMDB or sNewMDB and "Jet OLEDB:"?

> Thrse

Other Threads