[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

Automatically compact and repair nightly

I'm running WinXP with Access 2003 front end / back end databases.  I would like to automatically compact and repair the back end databases on a regular basis.  My question is:

1.  How frequently should I be running the compact and repair?
2.  What is the most efficient way to accomplish this?  

I've read questions about using an automated task, and I've also read that I should make a back-up copy before doing the compact and repair.  Is that really necessary?  If so, then I guess I would need to do a backup first, and then compact and repair.  

What's the best approach for this?  Thanks.
0
DanielAttard
Asked:
DanielAttard
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
daniel,
check here

How to Compact Databases At a Scheduled Time
http://support.microsoft.com/?kbid=209979
0
 
Rey Obrero (Capricorn1)Commented:
or you could do it using the task scheduler
Control Panel>Scheduled Task

you need a .bat file to do this
0
 
flavoCommented:
c:\pathToAccess\access.exe c:\myDb.mdb /compact  inthe shedualer (as cap said)
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
jjafferrCommented:
Hi guys

What compact and repair does is,
it makes a copy of your database as db1.mdb in the same directory as your existing mdb,
then it compacts it,
Then deletes the original mdb,
then renames the db1.mdb to your original mdb name.
so you have to make sure there is enough space on your harddisk during this process,

So during this process if something went wrong,
then you will not have the original working mdb,
but rather the new corrupt mdb (it never happend to me so far, touch wood).

How frequently?
I guess it depends on how your mdb is structured,
for example, if you use temp tables and delete them,
then Access will not release this empty space, unless you compact and repair,
so in this case, you will have to watch, after how many usages the mdb grows big,
so you make your code in such a way that will count how many times the mdb was used/open,
OR check its size compared to a size on a particular date, then do the compact and repair automatically with code.

But if your mdb was only updating records and adding records, then your compact and repair shold be with longer time interval.

Both capricorn1 and flavo have given you the way to compact and repair,
but if you are interested in a code that would check the size of the mdb then do comapct and repair, then check here:
http://www.experts-exchange.com/Databases/MS_Access/Q_20291042.html


jaffer
0
 
MootherCommented:
You can use this handy compacting app. Also does backups!

http://www.peterssoftware.com/cal.htm

M
0
 
DanielAttardAuthor Commented:
Thanks for the ideas everyone.  I like the idea of simply adding a scheduled task to accomplish the compact and repair operation since I already have a couple of scheduled tasks that I need to monitor from time to time, so adding another one seems like a logical solution to this issue.  One remaining question though.  

If I'm not particularly concerned about database bloat (because I don't use temporary tables), what other reason would there be for me to do a regularly scheduled compact and repair?  Should this process be done on a regular basis just for the heck of it, say on a monthly or weekly basis, or should I just leave the damn thing along since the size is not growing.  I'm just concerned with the possibility of corruption making its way into the database somehow, and I want to try and catch it at the earliest possible opportunity.

I'm worried that perhaps I could be doing "too much" to protect my data.  

p.s.  I also checked out that utility from Peterssoftware.com, and it worked like a charm.  Seems like an easy way to compact and create backups.  

0
 
MootherCommented:
You're quite right to add it to your nightly shedule (using the cal app above is easy as you now know.) because it might help save potential problems.

Not only will compacting your DB regularly protect it against corruption but making regular backups can help you trace unexplained data irregularities. My colleagues know not to screw with my data because I can always catch them out!

I run a small app which gathers around 20meg in the back end per year and it occasionally became inaccessible due to corruption but now that it gets compacted (2x per week) it doesn't show any signs of collapse. I also don't use temp tables but the thing can swell to double its size if left unattended.

Good Luck,

M
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now