[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Packing Access Database

Posted on 2001-08-03
5
Medium Priority
?
182 Views
Last Modified: 2010-04-06
I know I've seen this before, but the Search function in EE has been going haywire and I'm getting timeouts. So I'm asking again, how do I pack an Access database?
0
Comment
Question by:DragonSlayer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6349774
Hello

 Here's what you asked for :)

uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
  dao: OLEVariant;
begin
  dao := CreateOleObject('DAO.DBEngine.35');
  dao.CompactDatabase('C:\My Documents\DB1.mdb',
'C:\My Documents\CompactedDB1.mdb');
end;

Best regards
Mohammed Nasman
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 6349786
also here's how to compact access 2000 database, I didn't test it cuz i'm home and i dont' have access 2000 in home

//=======

Function CompactAndRepair(sOldMDB : String; sNewMDB : String) : Boolean;
const
         sProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;';
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;


Example :

if CompactAndRepair('e:\Old.mdb', 'e:\New.mdb') then
   ShowMessage('Successfully')
else
   ShowMessage('Error?');

Important Notes:
1- Include the JRO_TLB unit in your uses clause.
2- Nobody should use or open the database during compacting.
3- If the compiler gives you an error on the JRO_TLB unit follow these steps:
a) Using the Delphi IDE go to Project ? Import Type Library.
b) Scroll down until you reach ?Microsoft Jet and Replication Objects 2.1 Library?.
c) Click on Install button.
d) Recompile a gain.


Mohammed
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6349880


implementation

{$R *.DFM}

   const
  ODBC_ADD_DSN = 1;

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


procedure CompactMDB;
var
  sCompactDB, sCompactedDB: string;
 
begin
  sCompactDB := 'C:\DataBaseDir\TheDataBase.mdb';
  sCompactedDB := 'C:\DataBaseDir\CompactedTheDataBase.mdb';
  if not SQLConfigDataSource(0, ODBC_ADD_DSN,
    'Microsoft Access Driver (*.mdb)', PChar(
    'COMPACT_DB=' + sCompactDB + ' ' + sCompactedDB + ' General'#0)) then
     ShowMessage('Problems with compacting ' + sCompactDB + ' could not compact');
end;

end.


The Crazy One
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6351055
Hello DragonSlayer

  I test the second code I gave to you, it's work fine with Acess2000 and AccessXP (2002), so now you can Compact anydatabase with it :)

Mohammed
0
 
LVL 14

Author Comment

by:DragonSlayer
ID: 6351145
Thanks mnasman!

Sorry crazyone, but mnasman's a tad bit faster... and it doesn't require linking to external DLL.

mnasman, how do I know whether or not the database is currently opened by other programmes, because I open it as ShareReadWrite.
Thanks again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question