Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, how are you, could tell me how can i compact DB Access 2000 in my webpage (internet).
Email:chuchufuentes@hotmail.com
Thank you :sigh:
Posted

1 solution

I found this in some old code, but don't think I ever tried it and have no idea where it came from, but you might give it shot.
C#
/// <summary>
/// !!IMPORTANT!!
/// !make sure there's no open connections to your db before calling this method!
/// !!IMPORTANT!!
/// </summary>
/// <param name="connectionString">connection string to your db</param>
/// <param name="mdwfilename">FULL name of an MDB file you want to compress.</param>

public static void CompactAccessDB(string connectionString, string mdwfilename)
{
    object[] oParams;

    //create an inctance of a Jet Replication Object
    object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));

    //filling Parameters array
    //change "Jet OLEDB:Engine Type=5" to an appropriate value
    // or leave it as is if you db is JET4X format (access 2000,2002)
    //(yes, jetengine5 is for JET4X, no misprint here)

    oParams = new object[] { connectionString, "Provider=Microsoft.Jet.OLEDB.4.0;Data" + 
                            " Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5"};

    //invoke a CompactDatabase method of a JRO object
    //pass Parameters array
    objJRO.GetType().InvokeMember("CompactDatabase",
        System.Reflection.BindingFlags.InvokeMethod,
        null,
        objJRO,
        oParams);

    //database is compacted now
    //to a new file C:\\tempdb.mdb

    //let's copy it over an old one and delete it
    System.IO.File.Delete(mdwfilename);
    System.IO.File.Move("C:\\tempdb.mdb", mdwfilename);

    //clean up (just in case)
    System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO);
    objJRO = null;
}


Maybe that'll give you some ideas of what to google anyway.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900