How can I programmatically repair (not merely compact) an Access .mdb file?

后端 未结 4 1234
渐次进展
渐次进展 2021-01-15 13:48

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

相关标签:
4条回答
  • 2021-01-15 14:21

    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.

    0 讨论(0)
  • 2021-01-15 14:22

    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.

    0 讨论(0)
  • 2021-01-15 14:23

    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.

    0 讨论(0)
  • 2021-01-15 14:40

    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>")
    
    0 讨论(0)
提交回复
热议问题