Results 1 to 8 of 8

Thread: [RESOLVED] How to Compact Database

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    52

    Resolved [RESOLVED] How to Compact Database



    Is it possible to "compact and repair" an ms access database from a VB.net program. How could i do it? please advice.

    Thanks

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to Compact Database

    There is something in the sample in my sig that tackles such although it's in C# but I believe the conversion would be easy...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    52

    Re: How to Compact Database

    Thanks Dee...but I'm not sure which file is the code in? could you please let me know which file or if you could paste the code here would help.

    The sln and the csproj files dont open with my version of .net. I'm using VB.net 2002.

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: How to Compact Database

    if you use dao then use this statement

    DBEngine.CompactDatabase SourceDBName, DestinationDBName
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: How to Compact Database

    In your VB.NET project, add a reference to Microsoft Jet and Replication Objects 2.x Library by opening Project Menu, select Add Reference and then select COM Tab. And you can use this class to Compact and repair the database
    VB Code:
    1. Imports JRO
    2. Public Class JetReplication
    3.     Public Shared Function compactRepairMDB(ByVal sourceMDBPath As String, ByVal targetMDBPath As String) As Boolean
    4.         Dim jetReplicationObject As New JetEngineClass
    5.  
    6.         Try
    7.             jetReplicationObject.CompactDatabase( _
    8.                 "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" _
    9.                 & sourceMDBPath, "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" _
    10.                 & targetMDBPath)
    11.         Catch ex As Exception
    12.             Return False
    13.         End Try
    14.         Return True
    15.     End Function
    16. End Class
    Call the function like this
    VB Code:
    1. JetReplication.compactRepairMDB("C:\db1.mdb", "C:\db2.mdb")
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    52

    Re: How to Compact Database

    Thank you So much Shuja. The code works perfectly well.


    Just curious to know why was there a source and a target file. Cant it be Compacted to the same database?

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [RESOLVED] How to Compact Database

    What you may do is after compacting the original database you would have to delete it then rename the compacted database as your original database...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    52

    Re: [RESOLVED] How to Compact Database

    yep..did that already..thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width