J - C Sharper
J - C Sharper

Reputation: 1697

An MDB File is created programmatically from ADOX extension. Is this file size abnormally large?

I used the code in this forum to create a method to export DataSet object to MDB file: http://www.xtremedotnettalk.com/showthread.php?t=93599

My DataSet contain only one table, 5 columns with about 100k rows. The size of MDB file that produced is 50 MB. I wonder if it is too abnormally large?

Please let me know if you have better method of exporting DataSet to MDB file for smaller file size.

Upvotes: 0

Views: 308

Answers (2)

J - C Sharper
J - C Sharper

Reputation: 1697

I have found a way to Repair and Compact the MDB File programmatically:

    private static void CompactAndRepairMDB(string FilePath)
    {
        string FileName      = Path.GetFileNameWithoutExtension(FilePath);
        string FileName_Temp = Path.GetFileNameWithoutExtension(FilePath) + "_CompactAndRepair";

        string FilePath_Temp = FilePath.Replace(FileName, FileName_Temp);

        JRO.JetEngine oJetEngine = new JRO.JetEngine();

        string SourceConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                      "Data Source=" + FilePath + ";" + 
                      "Jet OLEDB:Engine Type=5;";

        string DestConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source=" + FilePath_Temp +";" +
                    "Jet OLEDB:Engine Type=5;";

        //Compact the database (makes a new copy)
        oJetEngine.CompactDatabase(SourceConn, DestConn);

        //Overrite the old new
        File.Copy(FilePath_Temp, FilePath, true);

        //Delete Temp File
        File.Delete(FilePath_Temp);
    }

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 416039

50MB * 1024KB/MB * 1024byte/KB = 52428800 bytes.

52428800 / 100000 rows / 5 columns/row = ~105 bytes per column.

Depending on how you defined your columns, this may not be out of line... especially when we have yet to consider any indexes, page size and padding, etc.

Upvotes: 1

Related Questions