11. juni 2002 - 17:00Der er
23 kommentarer og 1 løsning
Komprimering af Access DB
Kan man komprimere en Access database fra VB6 ? Når man fylder mange data i tabeller og derefter sletter mange data, forbliver størrelsen på Access DB filen den max værdi som blev opnået da der var mange data. Fra Access kan man komprimere filen - kan det også lade sig gøre fra VB6 ?
Tak Terry. Jeg vil prøve dette inden for de næste par dage (er lidt hængt op lige nu) og vende tilbage til dig med 30 point hvis det kører. Iflg. dette skulle det kunne lade sig gøre selv om det er lavet til VB5 - jeg er rimelig overbevist om at det også kan køre på VB6.
Private Sub Form_Load() Shell "C:\Programmer\Microsoft Office\Office\MSAccess.exe C:\DataServer\Tabeller\GrundData\Kunder.mdb /Compact", vbMinimizedNoFocus End Sub
Terry is right - it should be from VB. No from within Access. I will try and get some time tonight to test it out and come back to you. Good hint about the command line options, though.
Ja men det kræver at brugeren har Access installeret for at bruge det og det er ikke acceptabelt hvis han ikke skal bruge det til andre ting (koster ekstra for brugeren). Det kan selvfølgelige være nødvendigt hvis VB metoden ikke virker - så må brugeren æde de ekstra omkostninger (og så får du selvfølgelig dine point ;-)
Terry, I get this: "The mdbCompact utility requires Access to be running! Please confirm that Access is currently running and try again!" And when I start Access both with and without the db file that I try to compress: "The mdbCompact utility couldn't locate Access instance!" This comes when I use the db file as argument to the program call with or without full path. Any suggestions ? Can it do the job without Access running at all ?
No. I really would like a solution where no Access is required to be installed. What I am considering is to have two DB files - one with the data (tables) in and the other one just empty. Then make a temp copy of the empty to a temp file name, connect to both databases, read all objects from the db with data and save the objects to the temp db. Then close both DB's, kill the original and rename temp to original. A little novice-like, but is managable. Thinking about how the compress function works from within Access, something similiar happens. What do you think ?
I have found a solution which SHOULD work although I dont seem to be able to get it to. I have just updated to MDAC 2.6 and suspect this is the problem. Anyway try this!
To compact MDB databases using ADO, just include a reference to the 'Microsoft Jet and Replication Objects 2.6 Library' (distributed with the MDAC 2.6 package) in your VB project. The code folows:
Dim Jro As New JetEngine Jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\db.mdb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\new_db.mdb;Jet OLEDB:Engine Type=4"
You will obviously need to make some code to delete the original and re-name the new!
Ok now I have it working! Dim Jro As New JetEngine Jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\db.mdb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\new_db.mdb"
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.