|
-
Mar 30th, 2006, 04:41 AM
#1
Thread Starter
Member
[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
-
Mar 30th, 2006, 04:51 AM
#2
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...
-
Mar 30th, 2006, 05:07 AM
#3
Thread Starter
Member
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.
-
Mar 30th, 2006, 05:19 AM
#4
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.
-
Mar 30th, 2006, 05:30 AM
#5
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:
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 Class
Call the function like this
VB Code:
JetReplication.compactRepairMDB("C:\db1.mdb", "C:\db2.mdb")
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 30th, 2006, 08:11 PM
#6
Thread Starter
Member
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?
-
Mar 30th, 2006, 09:27 PM
#7
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...
-
Mar 30th, 2006, 11:56 PM
#8
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|