3

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! :-)

2 Answers 2

9

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to be of service. If you think my answer is the correct answer to your question you could mark my answer as accepted. That is how StackOverflow works. Thank you in advance.
2

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".

5 Comments

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?
As far as I know, ADOX is already installed on XP and higher, just like ADO. Wikipedia says that MDAC 2.5 includes ADOX and was included in Windows starting with Windows 2000.
I see. Now I know. Thanks! :)
Be aware that the jet driver does not support 64-bit applications, so you will be limited to 32 bit apps.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.