2

I have a corrupt database. If I open it in MS Access, MS Access offers to repair it, and it succeeds.

How can I do that with code? On a machine where MS Access is not installed.

I know from trying it that JRO.JetEngine.CompactDatabase does NOT work.

In other words, I want to do what Access or JETCOMP.exe is doing, not what JRO.JetEngine.CompactDatabase is doing.

Corey Trager
  • 22,649
  • 18
  • 83
  • 121
  • Er, have you tried JetComp? If it doesn't work, there is no way to repair the database with any Microsoft-provided tools, and you need to engage someone who recovers corrupted Jet MDBs. I recommend Peter Miller at http://pksolutions.com. – David-W-Fenton Sep 28 '08 at 22:06

4 Answers4

2

You need to go to http://support.microsoft.com and search for the JetComp.exe utility, which will attempt to repair and compact your MDB without opening the file. The reason none of the suggestions above work is because they have to open the MDB to do their work, whereas JetComp doesn't open the file, but operates on it structurally.

If it can't recover your file (which does happen), then you'll have to go to a data recovery service. I recommend Peter Miller of PKSolutions.com.

sth
  • 222,467
  • 53
  • 283
  • 367
David-W-Fenton
  • 22,871
  • 4
  • 45
  • 58
  • Not the answer because I want to do it "programmatically". – Corey Trager Sep 29 '08 at 23:29
  • I'm afraid you're out of luck, then. – David-W-Fenton Sep 29 '08 at 23:36
  • BTW, what's wrong with the architecture of your app that you know your users will need extraordinary tools to repair corrupted MDBs? There is no reason why you should expect MDBs to corrupt (it's the exception rather than the rule in a well-architected app). Maybe you shouldn't be using Jet, – David-W-Fenton Sep 29 '08 at 23:40
1

Command-line switch for opening a .mdb file:

/compact

It repairs and compacts the database file.

If you leave out a target file name following the /compact switch, the file is compacted to the original name and folder. To compact to a different name, specify a target file.

micahwittman
  • 12,356
  • 2
  • 32
  • 37
1

Have you tried DBEngine.RepairDatabase [my.mdb]? (which doesn't seem to work any more even when you reference an earlier version)

However, if is happening so often that you need to code it, you probably have a bigger problem you should be solving first.

If you are willing to use separate utility, how about the Jetcomp.exe utility (http://support.microsoft.com/kb/295334 ). It is supposed to "be able to recover some databases that the Microsoft Access compact utility and the CompactDatabase method cannot." In which case, all you need to do is execute the external application.

e.g.,

Call Shell("Jetcomp.exe <arguments>")
BIBD
  • 15,107
  • 25
  • 85
  • 137
  • But see, http://support.microsoft.com/kb/294966: PRB: RepairDatabase Method Is No Longer Available in DAO 3.6 – Corey Trager Sep 26 '08 at 20:55
  • But have you tried JetComp? It has nothing to do with the problem in that article, as it's a standalone executable. – David-W-Fenton Sep 28 '08 at 22:08
  • 1
    BTW, Repair as a separate operation was removed from Access with Access97 SR2, because people were repairing undamage MDBs and it was corrupting them. Since then, every COMPACT operation first checks if the MDB needs to be repaired, and repairsi t if it needs to. Thus, to repair, execute a compact. – David-W-Fenton Sep 28 '08 at 22:09
  • JetComp is fine, but I don't want to ship JetComp. I want to build its functionality into my app. That's what I meant by "programmatically". – Corey Trager Sep 29 '08 at 23:32
  • You can't do it. Period. Unless you can figure out how to reverse engineer the Jet DLLs. Good luck with that -- I certainly wouldn't recommend it. I don't know why you don't want to include the one tool MS provides for this purpose. – David-W-Fenton Sep 29 '08 at 23:35
  • 1
    Then I don't think it's doable. And it's probably not worth your effort to find a way - really this should be a rare event. Add a FAQ on how to fix a corrupt database. Or one better, fix the problem at is source. Switch to a more-reliable free database (MySQL, the runtime MS SQL, etc.) – BIBD Sep 30 '08 at 16:04
0

I'm not a MS Acccess guru, but it appears as though this utility contains the DLLs you'd need to compact and repair a corrupt database file.

Huuuze
  • 15,528
  • 25
  • 72
  • 91