My service applications use access databases, which need to be regularly compacted. I use this code:
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?
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?