Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Automatically compact and repair nightly

Posted on 2004-09-30
7
605 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 12194065
daniel,
check here

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

Expert Comment

by:Rey Obrero (Capricorn1)
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

860 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