Compacting MS Access dari Delphi


Ini ada artikel dari teman via email, yang bisa digunakan untuk melakukan compacting database MS Access dari Delphi. Udah pernah aku coba dan bekerja dengan baik. Postingan ini dimuat atas permintaan Mas Rahman Delphindo. Semoga bermanfaat juga buat yang lain, semoga.

berikut source yang saya dapatkan dari teman saya,
semoga nggak binun baca source nya 🙂

unit unCompact;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls, ComObj ;

type
TfmCompact = class(TForm)
Panel1: TPanel;
BtCompact: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BtCompactClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
DBYangAkanDiCompact, PwdDBYangAkanDiCompact : String ;
end;

const
CompactDB = ‘CpMyBIZ.mdb’ ;

var
fmCompact: TfmCompact;

implementation

uses unGlobalUnit, undmMainMenu ;

{$R *.dfm}

procedure TfmCompact.FormClose(Sender: TObject; var Action: TCloseAction); begin
Action := CaFree ;
end;

procedure TfmCompact.BtCompactClick(Sender: TObject);
var A : Variant;
begin
if FileExists(CompactDB) then
begin
DeleteFile(CompactDB) ;
end ;
Try
ShowSPLASH ;
A := CreateOLEObject(‘JRO.JetEngine’) ;

// jika DB tidak di password
{
A.CompactDatabase(‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + unGlobalUnit.DataSource,
‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + CompactDB +
‘;Jet OLEDB:Encrypt Database=True’) ;
}

// jika DB ada password nya
A.CompactDatabase(‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + DBYangAkanDiCompact + ‘;Jet OLEDB:Database Password=’ + PwdDBYangAkanDiCompact ,
‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + CompactDB +
‘;Jet OLEDB:Encrypt Database=True’ + ‘;Jet OLEDB:Database Password=’ + PwdDBYangAkanDiCompact) ;
A := UnAssigned ;

DeleteFile(DBYangAkanDiCompact) ;
RenameFile(CompactDB, DBYangAkanDiCompact) ;
DeleteFile(CompactDB) ;
HideSPLASH ;
MessageDlg(‘Compact sukses dilakukan’,mtInformation,[mbOK],0) ;
Close ;
Except
on E: Exception do
begin
HideSPLASH ;
MessageDlg(‘Compact gagal dilakukan : ‘ + E.Message , mtInformation, [mbOK], 0) ;
end ;
End ;
end;

end.

=============================================================

Iklan

Posted on Desember 12, 2006, in Pemrograman and tagged , . Bookmark the permalink. Tinggalkan komentar.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: