Solved

Automatically compact and repair nightly

Posted on 2004-09-30
7
601 Views
Last Modified: 2010-08-05
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
Comment
Question by:DanielAttard
7 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 12194065
daniel,
check here

How to Compact Databases At a Scheduled Time
http://support.microsoft.com/?kbid=209979
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 12194087
or you could do it using the task scheduler
Control Panel>Scheduled Task

you need a .bat file to do this
0
 
LVL 34

Expert Comment

by:flavo
ID: 12194392
c:\pathToAccess\access.exe c:\myDb.mdb /compact  inthe shedualer (as cap said)
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 27

Assisted Solution

by:jjafferr
jjafferr earned 200 total points
ID: 12194780
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
 
LVL 3

Expert Comment

by:Moother
ID: 12194931
You can use this handy compacting app. Also does backups!

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

M
0
 

Author Comment

by:DanielAttard
ID: 12196873
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
 
LVL 3

Accepted Solution

by:
Moother earned 300 total points
ID: 12197571
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 run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now