Add a reference to “Microsoft Office 12.0 Access Database Engine Object Library”.
And write a following code to compact the Access 2007 Database:-
// Create a new object of DBEngine
Microsoft.Office.Interop.Access.Dao.DBEngine objDbEngine = new Microsoft.Office.Interop.Access.Dao.DBEngine();
// Call the CompactDatabase method on object of DBEngine
objDbEngine.CompactDatabase(“C:\SourceDB.accdb”, “C:\TargetDB.accdb”, null, null, ";pwd=passwordOfDatabaseIfAnyElseNULL");
For more information about the function parameters refer to the following link:-
http://msdn.microsoft.com/en-us/library/bb220986.aspx
And write a following code to compact the Access 2007 Database:-
// Create a new object of DBEngine
Microsoft.Office.Interop.Access.Dao.DBEngine objDbEngine = new Microsoft.Office.Interop.Access.Dao.DBEngine();
// Call the CompactDatabase method on object of DBEngine
objDbEngine.CompactDatabase(“C:\SourceDB.accdb”, “C:\TargetDB.accdb”, null, null, ";pwd=passwordOfDatabaseIfAnyElseNULL");
For more information about the function parameters refer to the following link:-
http://msdn.microsoft.com/en-us/library/bb220986.aspx
Above code of CompactDatabase will do the compact for .MDB file? or is it only for .accdb. I tried using .mdb but its giving error. Please let me know if we can you this code for .mdb using Microsoft.Office.Interop.Access.Dao.DBEngine objDbEngine = new Microsoft.Office.Interop.Access.Dao.DBEngine(); ?
ReplyDeleteThis Access Recovery can recover deleted databases quickly and automatically. Its unEraser engine with PowerSearch technology thoroughly scans the hard drive to find and recover all Microsoft Access databases on the disk.
DeleteThe above code will work only for the Access 2007 format, that is .accdb. To format the .mdb files you have to use the JRO object. The following link would be certainly of your help - http://www.codeproject.com/KB/database/CompactAndRepair.aspx
ReplyDeleteThanks so much for this...
ReplyDeleteYogi:
ReplyDeleteNice. You helped me. Thank you!!!
José.
Thanks for the code. Should the target computer have Microsoft Access 2007 installed? or Which file I have to redistribute?
ReplyDeleteIt is not mandatory to have Microsoft Access 2007 installed on the target computer. But in that case you need to have AccessDatabaseEngine installed, in order to get your application working. You may refer my earlier post http://techieyogi.blogspot.com/2009/11/installing-access-database-engine-with.html on detailed instructions.
ReplyDeleteThanks, helped me fix some Access weirdness!
ReplyDeleteThat's a really helpful post, thanks. Works a treat for me and my customer.
ReplyDeleteHello sir,
ReplyDeleteI have completed an access database. There is no problem for me to connect this database and show data. Please tell me how to connect MS Access form in asp.net with VB and run all of macros ??????What namespace to imports and how to use the object or classes? The access form(s) will show when I click button and it will run access macros.
Annie
Hi Annie
DeleteYou can connect to access database using ado.net, and use it as your data source with connection string given here - "https://www.connectionstrings.com/access/".
However I don't think running macros will be possible from asp.net.
You need to use access file only for this purpose because this is how it is designed, as an application with GUI, macros, forms etc, and not just database source.
Thanks.
I need code for compact the MS access database 2002 or 2003 using VB6
ReplyDeleteYou can try to use third party Access file recovery software to recover your lost and corrupted data from .mdb files. For more details about this software:- http://www.recoverydeletedfiles.com/access-file-recovery-tool.html
ReplyDelete/"
Access File Recovery Tool that easily repairs corrupt MS Access (.MDB or .ACCDB) database file and then recover tables, queries, forms, macros, reports, etc. It also restores permanently deleted data from MDB file of MS Access 2013, 2010, 2007, 2003, 2002, 2000 on your latest Windows 8.1 PC & all below Windows version like as Win8, Win7, Vista, 2003 and XP.
ReplyDeleteDownload:- http://www.filesrecoverytool.com/access-file-recovery.html
I would like to suggest this application, which will repair your access data in trial version and see you the preview of recover data. http://www.recoverfilesdownload.com/access-file-recovery.html
ReplyDeleteMS Office 14 should be able to handle both accdb and older access format such as 2007 .mdb
ReplyDeleteYour blog has given me that thing which I never expect to get from all over the websites. Nice post guys!
ReplyDeleteThis free data recovery software provides easy and quick data recovery solutions to recover your lost data. Generally, if the lost access file is not damaged or overwritten, visit here:- https://www.recoverydeletedfiles.com/access-file-recovery-tool.html
ReplyDeleteThank You and I have a nifty provide: Whole House Renovation Cost Calculator home renovation near me
ReplyDelete