ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

Quick query design
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Compact An Access Database File From ASP

If you work with Access databases from ASP, you probably occasionally find you need to download the whole thing to make a change. If your site is database transaction intensive you might find that you spend hours downloading the mdb file only to have it contain very little data. What if you could compact your mdb files on the server before you download them? Now you can...

The CompactDatabase method of the JetEngine object (available in ADO 2.1 and later I believe) copies and compacts a database into a new mdb file. You can't compact a database in place (compact a file to a new file with the same name), but being able to compact on the server can be useful none the less. Here's a piece of sample code for you to work from:

Dim objJetEngine
Set objJetEngine = Server.CreateObject("JRO.JetEngine")
objJetEngine.CompactDatabase _
    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
        & Server.MapPath("source.mdb") & ";", _
    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
        & Server.MapPath("destination.mdb") & ";"
Set objJetEngine = Nothing

As you can see, the CompactDatabase method takes two parameters: an ADO connection string identifying the source database and another identifying the destination. You'll need to be sure you have the appropriate NTFS permissions to create the new file, but beyond that it's a pretty simple procedure.

For more information you might want to read Microsoft's Knowledge Base article: HOWTO: Compacting Microsoft Access Database via ADO. If you need to handle more advanced issues like Encrypted Databases, System Databases, Jet Engine Types, etc. then you might find the two sections on properties of the collection object in ADO Provider Properties and Settings useful, but please note that this method only supports a subset of the properties listed there.

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers