Board index » delphi » ADO - Jet 4 - MS Access - Compacting - D6

ADO - Jet 4 - MS Access - Compacting - D6

Hi,

Does anyone know how to compact a MS Access database from within my Delphi 6
application through ADO (& JET 4) ?!?

--
Gerrit Menkveld

Handata B.V.
g.menkv...@handata.nl

 

Re:ADO - Jet 4 - MS Access - Compacting - D6


Quote
>Does anyone know how to compact a MS Access database from within my Delphi 6
>application through ADO (& JET 4) ?!?

First ADO does not directly support Compact.  You need to import the JRO type
library (msJro.dll)

Then you can use code similar to this

procedure TMainForm.CompactDataBa{*word*224}uClick(Sender:
TObject;strGlobalAccessVersion,strGlobalPath:String);
var JROJetEngine: TJROJetEngine;
    strTempDBPath,
    strSource,
    strDest,
    strJetVersion: string;
    iLength: integer;
begin
  if strGlobalAccessVersion = '2000' then
    strJetVersion := '5'  { Access 2000}
  else if strGlobalAccessVersion = '97' then
    strJetVersion := '4';   {Jet 3.x, Access 97}
  strTempDBPath := ExtractFilePath(strGlobalDBPath) + 'TEMP.MDB';
  strSource := 'Data Source=' + strGlobalDBPath + ';Jet OLEDB:Engine Type='
              + strJetVersion;
  strDest := 'Data Source=' + strTempDBPath + ';Jet OLEDB:Engine Type=' +
               strJetVersion;
  try
    try
      Screen.Cursor := crHourGlass;
      if not dbModule.CloseAll then
        begin
          MessageDlg('Error closing some datasets, unable to compact',
               mtError, [mbOk], 0);
          exit;
        end
      else
        dbModule.ADOConnection1.Close;
      Application.ProcessMessages;
      JROJetEngine := TJROJetEngine.Create(Application);
      JROJetEngine.CompactDatabase(strSource, strDest);
      SysUtils.DeleteFile(strGlobalDBPath);
      RenameFile(strTempDBPath, strGlobalDBPath);
      MessageDlg('The database has been packed', mtInformation, [mbOk], 0);
    except
      on E: Exception do
        MessageDlg('Error packing database: ' + E.Message, mtError, [mbOk],0);
    end;
  finally
    JROJetEngine.Free;
    dbModule.ADOConnection1.Open;
    Screen.Cursor := crDefault;
  end;
end;
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:ADO - Jet 4 - MS Access - Compacting - D6


The following procedure works great for me. Do I really need all that other
code you have added Brian ?

begin
  var
    fJetEngine : JetEngine;
  Begin
    fJetEngine := CoJetEngine.Create;
    try
    fJetEngine.CompactDatabase('Data
Source=D:\temp\Delphi\plugins\dfk.mdb','Data
Source=D:\temp\Delphi\plugins\your_compacted_db.mdb');
finally
  fJetEngine :=nil;
end

Re:ADO - Jet 4 - MS Access - Compacting - D6


Quote
"Steve" <s...@icon.co.za> wrote in message news:3b364a91_1@dnews...

| The following procedure works great for me. Do I really need all that
other
| code you have added Brian ?
|
| begin
|   var
|     fJetEngine : JetEngine;
|   Begin
|     fJetEngine := CoJetEngine.Create;
|     try
|     fJetEngine.CompactDatabase('Data
| Source=D:\temp\Delphi\plugins\dfk.mdb','Data
| Source=D:\temp\Delphi\plugins\your_compacted_db.mdb');
| finally
|   fJetEngine :=nil;
| end

Your code makes too many assumptions.  For example, it assumes that the
input file is Access 2000.  It also fails to delete the original file and
rename the newly compacted file.  It assumes it has exclusive access to the
input file.  Etc.

--

Quidquid latine dictum sit, altum viditur.
#319

Re:ADO - Jet 4 - MS Access - Compacting - D6


Thanks DRS.

'it assumes that the input file is Access 2000.' was what I was looking for
:))
I just didnt see why that version checking was needed...now i see why :)

Re:ADO - Jet 4 - MS Access - Compacting - D6


Brian could you please post the code you using to check to see whether
access 97 or access 2000 is installed? Thanks:)

Re:ADO - Jet 4 - MS Access - Compacting - D6


DRS,

Quote
DRS <d...@removethis.ihug.com.au> wrote in message news:3b3662fa_2@dnews...
> Your code makes too many assumptions.  For example, it assumes that the
> input file is Access 2000.  It also fails to delete the original file and
> rename the newly compacted file.  It assumes it has exclusive access to
the
> input file.  Etc.

You can set the JetVersion := '0' and whatver version is installed is what
is used....!

Bill

Re:ADO - Jet 4 - MS Access - Compacting - D6


Quote
>Brian could you please post the code you using to check to see whether
>access 97 or access 2000 is installed? Thanks:)

I don't have that piece of code.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:ADO - Jet 4 - MS Access - Compacting - D6


Quote
"Bill Richards" <bi...@icehouse.net> wrote in message

news:3b368d22_2@dnews...

Quote
> DRS,
> You can set the JetVersion := '0' and whatver version is installed is what
> is used....!

Bill where can I use JetVersion := '0'  ?

I currently have
var
  MSJetEngine: JetEngine;

MSJetEngine.JetVersion doesnt exist.

Other Threads