Solved

Automatically compact and repair nightly

Posted on 2004-09-30
7
602 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

943 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

10 Experts available now in Live!

Get 1:1 Help Now