views:

115

answers:

2

Hi, Is there a way to create Access databases (.mdb) without actually using Ms Access? I'd like my app to create it instead (when user presses "New Document" on the toolbar).

I'm using Delphi 5 Ent.

Thanks in advance! :-)

+1  A: 

This is how it's done:

procedure CreateNewDatabase;
var
  AdoxCatalog: Catalog;
begin
  AdoxCatalog := CoCatalog.Create;
  AdoxCatalog.Create(ConnectionString
    + 'Jet OLEDB:Engine Type='+IntToStr(Jet4x)+';');
end;

You will need ADOX_TLB which you can get by importing type library "Microsoft ADO Ext. 2.8 for DDL and Security".

himself
Thanks for your answer. I'm planning to make my app a shareware. How the use of ADOX would affect the deployment? Do I need to include the ActiveX library too or just the app.exe?
AFF
As far as I know, ADOX is already installed on XP and higher, just like ADO. [Wikipedia](http://en.wikipedia.org/wiki/Microsoft_Data_Access_Components) says that MDAC 2.5 includes ADOX and was included in Windows starting with Windows 2000.
himself
I see. Now I know. Thanks! :)
AFF
Be aware that the jet driver does not support 64-bit applications, so you will be limited to 32 bit apps.
skamradt
There is now 64-bit support for Access files. I'm not entirely clear on how ACE handles MDBs (some things about the way A2007/A2010 work suggest that Access uses Jet 4 for MDBs and ACE for ACCDBs, but other things suggest that ACE handles both), but if you need to compile for 64-bit you should try downloading the 64-bit ACE, which has been available on MS's website for quite some time.
David-W-Fenton
+3  A: 

Yes there is a way if you use the ADOX library. It is an ActiveX library you can import in Delphi. Then you can create a new database with the code below. See here.

procedure TForm1.btnNewDatabaseClick(Sender: TObject);
var
 DataSource : string;
 dbName     : string;
begin
 dbName:='c:\aboutdelphi.mdb';

 DataSource :=
    'Provider=Microsoft.Jet.OLEDB.4.0' +
    ';Data Source=' + dbName +
    ';Jet OLEDB:Engine Type=4';

  ADOXCatalog1.Create1(DataSource);
end;
Lars Truijens
Thanks for your answer :-)
AFF