Avatar billede itbjarne Nybegynder
11. juni 2002 - 17:00 Der 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 ?
Avatar billede terry Ekspert
11. juni 2002 - 17:21 #1
yes!
Avatar billede terry Ekspert
11. juni 2002 - 17:24 #2
Avatar billede itbjarne Nybegynder
11. juni 2002 - 17:38 #3
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.
Avatar billede proaccess Nybegynder
12. juni 2002 - 09:41 #4
>Terry: isn't that compact from WITHIN Access ???

>itbjarne: brug denne...

Private Sub Form_Load()
  Shell "C:\Programmer\Microsoft Office\Office\MSAccess.exe C:\DataServer\Tabeller\GrundData\Kunder.mdb /Compact", vbMinimizedNoFocus
End Sub
Avatar billede terry Ekspert
12. juni 2002 - 09:59 #5
Hi proaccess No it should be VB5!
Avatar billede itbjarne Nybegynder
12. juni 2002 - 10:28 #6
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.
Avatar billede proaccess Nybegynder
12. juni 2002 - 13:24 #7
"Here's a VB5 utility that lets you compact the current database from code WITHIN an Access 97 database."
Avatar billede itbjarne Nybegynder
12. juni 2002 - 13:28 #8
Yes, but I am sure the code would work from VB if the correct objects are referenced. I will try it out - let's see what happens.
Avatar billede proaccess Nybegynder
12. juni 2002 - 14:04 #9
VB5/6 har ikke CurrentDB indbygget...
Avatar billede itbjarne Nybegynder
12. juni 2002 - 14:20 #10
Nej men: DBConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\db\dbname.mdb;Persist Security Info=False;Jet OLEDB:System database=\db\dbperm.mdw"
Avatar billede proaccess Nybegynder
12. juni 2002 - 14:40 #11
OK for mig, do it your way...  Men bemærk lige "min" 1-linies funktion af 09:41:38 inden du bruger FOR meget krudt på Connectstrings m.v.
Avatar billede itbjarne Nybegynder
12. juni 2002 - 14:47 #12
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 ;-)
Avatar billede itbjarne Nybegynder
12. juni 2002 - 23:17 #13
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 ?
Avatar billede terry Ekspert
13. juni 2002 - 10:50 #14
itbjarne>have you tried proacess' solution with the shell function?
Avatar billede itbjarne Nybegynder
13. juni 2002 - 10:59 #15
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 ?
Avatar billede terry Ekspert
13. juni 2002 - 11:07 #16
Will get back as soon as possible, kind of busy at the moment!
Avatar billede itbjarne Nybegynder
13. juni 2002 - 11:20 #17
So you are not just sitting here answering on VB questions, eh' ?
Avatar billede terry Ekspert
13. juni 2002 - 11:38 #18
:o)
Avatar billede terry Ekspert
13. juni 2002 - 12:25 #19
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!

Hope you can get it to work!
Avatar billede terry Ekspert
13. juni 2002 - 12:35 #20
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"
Avatar billede itbjarne Nybegynder
13. juni 2002 - 12:48 #21
BINGO !
Works also with 2.5 library.
Thanks Terry - full points to you.
Avatar billede itbjarne Nybegynder
13. juni 2002 - 12:49 #22
(As if you didn't have enough !;-)
Avatar billede terry Ekspert
13. juni 2002 - 12:55 #23
thanks:o)
but what can I do with them?
Avatar billede itbjarne Nybegynder
13. juni 2002 - 13:04 #24
Give ME some!
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester