:confused:
Is it possible to "compact and repair" an ms access database from a VB.net program. How could i do it? please advice.
Thanks
Printable View
:confused:
Is it possible to "compact and repair" an ms access database from a VB.net program. How could i do it? please advice.
Thanks
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...
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.
if you use dao then use this statement
DBEngine.CompactDatabase SourceDBName, DestinationDBName
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 databaseCall the function like thisVB Code:
Imports JRO Public Class JetReplication Public Shared Function compactRepairMDB(ByVal sourceMDBPath As String, ByVal targetMDBPath As String) As Boolean Dim jetReplicationObject As New JetEngineClass Try jetReplicationObject.CompactDatabase( _ "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" _ & sourceMDBPath, "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" _ & targetMDBPath) Catch ex As Exception Return False End Try Return True End Function End ClassVB Code:
JetReplication.compactRepairMDB("C:\db1.mdb", "C:\db2.mdb")
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?
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...
yep..did that already..thanks :)