Board index » delphi » MS Access compact and repair

MS Access compact and repair

There are 3 ways:
- Using DAO (the BDE MSACCESS driver uses DAO)
- Using ODBC (if you are using BDE ODBC)
- Using ADOX/JRO (if you are using ADOExpress)

Which one are you looking for ?

"De Kapitein" <capt...@theship.com> schreef in bericht
news:9bjhvj$jmo$1@porthos.nl.uu.net...

Quote
> Hi,

> While working with an MS Access db (creating records, throwing them away)
my
> EMPTY database grew up to 45 MB, while the original db was about 700K.
Doing
> compact and repair using MS Access decreased the size again, but is there
a
> way to do this compacting from within my Delphi app?

> Thanks.

 

Re:MS Access compact and repair


Quote
M.H. Avegaart <avegaartNOS...@mccomm.nl> wrote in message

news:9bmacs$16k$1@porthos.nl.uu.net...

Quote
> There are 3 ways:
> - Using DAO (the BDE MSACCESS driver uses DAO)
> - Using ODBC (if you are using BDE ODBC)
> - Using ADOX/JRO (if you are using ADOExpress)

> Which one are you looking for ?

I'm looking for the ODBC way,

Thanks.

Re:MS Access compact and repair


The following example demonstrates the use of SQLConfigDatasource for MS
Access databases:

const
  ODBC_ADD_DSN = 1; // Add data source
  ODBC_CONFIG_DSN = 2; // Configure (edit) data source
  ODBC_REMOVE_DSN = 3; // Remove data source
  ODBC_ADD_SYS_DSN = 4; // add a system DSN
  ODBC_CONFIG_SYS_DSN = 5; // Configure a system DSN
  ODBC_REMOVE_SYS_DSN = 6; // remove a system DSN
  ODBC_REMOVE_DEFAULT_DSN = 7; // remove the default DSN

function SQLConfigDataSource(
  hwndParent: HWND;
  fRequest: WORD;
  lpszDriver: LPCSTR;
  lpszAttributes: LPCSTR): BOOL; stdcall; external 'ODBCCP32.DLL';

function AddDSN(const DSN, Database, Description: String): Boolean;
begin
  Result := SQLConfigDataSource(0, ODBC_ADD_DSN,
    'Microsoft Access Driver (*.mdb)', PChar(
    'DSN=' + DSN + #0 +
    'Driver=ODBCJT32.DLL'#0 +
    'DBQ=' + Database + ''#0 +
    'DefaultDir=' + ExtractFilePath(Database) + #0 +
    'Description=' + Description + #0 +
    'FIL=MS Access'#0 +
    'UID=Admin'#0));
end;

function RemoveDSN(const DSN: String): Boolean;
begin
  Result := SQLConfigDataSource(0, ODBC_REMOVE_DSN,
    'Microsoft Access Driver (*.mdb)', PChar(
    'DSN=' + DSN + #0));
end;

function RepairDB(const Database: String): Boolean;
begin
  Result := SQLConfigDataSource(0, ODBC_ADD_DSN,
    'Microsoft Access Driver (*.mdb)', PChar(
    'REPAIR_DB=' + Database + #0 +
    'UID=Admin'#0 +
    'PWD=PWSWAN'#0));
end;

function CompactDB(const Database1, Database2: String): Boolean;
begin
  Result := SQLConfigDataSource(0, ODBC_ADD_DSN,
    'Microsoft Access Driver (*.mdb)', PChar(
    'COMPACT_DB=' + Database1 + ' ' + Database2 + ' General'#0 +
    'UID=Admin'#0 +
    'PWD=PWSWAN'#0));
end;

ps. Database filenames have to be put between quotes (") for RepairDB and
CompactDB on Jet 4.0.

"De Kapitein" <capt...@theship.com> schreef in bericht
news:9bmhcv$64a$1@porthos.nl.uu.net...

Quote
> M.H. Avegaart <avegaartNOS...@mccomm.nl> wrote in message
> news:9bmacs$16k$1@porthos.nl.uu.net...
> > There are 3 ways:
> > - Using DAO (the BDE MSACCESS driver uses DAO)
> > - Using ODBC (if you are using BDE ODBC)
> > - Using ADOX/JRO (if you are using ADOExpress)

> > Which one are you looking for ?

> I'm looking for the ODBC way,

> Thanks.

Re:MS Access compact and repair


Quote
M.H. Avegaart <avegaartNOS...@mccomm.nl> wrote in message

news:9bmhp1$6bu$1@porthos.nl.uu.net...

Quote
> The following example demonstrates the use of SQLConfigDatasource for MS
> Access databases:

Thanks a lot!

Other Threads