Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell what version an Access database is 1

Status
Not open for further replies.

Griffyn

Programmer
Jul 11, 2002
1,077
AU
My service applications use access databases, which need to be regularly compacted. I use this code:

Code:
[b]uses[/b]
  JRO_TLB;
[b]var[/b]
  cs : String;
[b]begin[/b]
  cs := [teal]'Provider=Microsoft.Jet.OLEDB.4.0;'[/teal]
    + [teal]'Jet OLEDB:Engine Type=4;Data Source='[/teal];
  [b]with[/b] TJetEngine.Create([b]nil[/b]) [b]do[/b]
    [b]try[/b]
      CompactDatabase(cs + [teal]'MyDB.mdb'[/teal], cs + [teal]'TempDB.mdb'[/teal]);
    [b]finally[/b]
      Free;
    [b]end[/b];
[b]end[/b];

Which works just fine for Access 97 databases. A bug in Access 97 means that for one of my services, I need it to use an Access 2000 database, and the above code fails unless I change the string to have Engine Type=5.

The compact code appears in a library unit. How can I have it detect which Engine Type it should use? I could try v4, allow the exception to happen and then try again with v5, but this seems inelegant. Is there a better method?
 
Thanks Glenn,

Working code:

Code:
[b]uses[/b]
  JRO_TLB;
[b]var[/b]
  cs : String;
  jv : Integer;
[b]begin[/b]
  FConnection.Open;  [navy][i]//existing TADOConnection to database
[/i][/navy]  jv := StrToIntDef(FConnection.Properties.Item[[teal]'Jet OLEDB:Engine Type'[/teal]].Value, [purple]4[/purple]);
  cs := Format([teal]'Provider=Microsoft.Jet.OLEDB.4.0;'[/teal]
    + [teal]'Jet OLEDB:Engine Type=%d;Data Source='[/teal], [jv]);
  [b]with[/b] TJetEngine.Create([b]nil[/b]) [b]do[/b]
    [b]try[/b]
      CompactDatabase(cs + [teal]'MyDB.mdb'[/teal], cs + [teal]'TempDB.mdb'[/teal]);
    [b]finally[/b]
      Free;
    [b]end[/b];
[b]end[/b];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top