How To Compact And Repair An Access Database From A Python Script
I have a python script running from an ArcGIS custom toolbox. The script deals with Access databases (mostly personal geodatabases). What I am wondering is, is there a way to compa
Solution 1:
Use Python's win32com library and make a call to the VBA method CompactRepair(). Do note, a backup file path is required (one that does not exist yet) during the process but can be deleted after successful compact, using os.remove()
for that need:
import os
import win32com.clientsrcDB='C:\\Path\\To\\Database.accdb'
destDB = 'C:\\Path\\To\\Database_backup.accdb'
oApp = win32com.client.Dispatch("Access.Application")
oApp.compactRepair(srcDB, destDB)
os.remove(destDB)
oApp = None
Solution 2:
I know this is old, but just an minor change to the code above to anyone using it in the future (I just had to use this now, thanks Parfait for posting this solution).
The line that states:
oApp = win32com.client.Dispatch("Access.Application")
should be
oApp = win32com.Dispatch("Access.Application")
thanks!
Post a Comment for "How To Compact And Repair An Access Database From A Python Script"