Can VB tell the correct state of an Access database?

Posted on 2005-04-27
Last Modified: 2013-12-25
VB6/Access97 application.  For the most part my multi-user application works fine, but occasionally the database gets corrupted, or dubious data is generated.

I'm creating a Database Maintenance form whereby Users can monitor the back end database and check all is well.  I'm putting in routines to tidy up tables if known errors have occurred.  There is also a standard DAO Compact and Repair facility ( much better I've found than using ADO/JRO ).
Now, is there a way of telling whether a database is so corrupted/damaged that C & R won't work?  I looked at one the other day that I couldn't repair and the only way to restore it was to create a new database and import the tables in.  The application was still working, so although Access recognised it had a problem it wasn't preventing normal reading and writing of data.

Can VB look at an Access database and tell whether it's OK, slightly corrupted and in need of C & R, or so corrupted that needs a blank database transfer?
Question by:drchutney
    LVL 8

    Accepted Solution

     First things first! BACKUP THE DATABASE!
    Before doing anything, make at least two backups of the corrupted database.


     How do you know if a database is corrupt?

     "Unrecognized database format" (When your database was operating under your current version of Access before)

     "Enter database password" (when none was set)

     "The Microsoft Jet Database Engine cannot open the file"

     "Visual Basic for Applications Project in This Database Is Corrupt"

     "Unexpected Error 35012"

     An "Invalid Page Fault..." error (not necessarily a corrupt database issue)

     "You do not have the necessary permissions to open this object. Please contact your system administrator."

     [database.mdb] isn't an Index in this table. Look in the index collection of the TableDef object to determine the valid index names

     The Microsoft Jet database engine stopped the process because you and another user are attempting to change the same data at the same time -- 3197

     'Microsoft Access has encountered a problem and needs to close'

     The database 'databasename.mdb' needs to be repaired or isn't a Microsoft Access database file. -- 2239

     Operation failed - too many indexes - reduce the number and try again

     Failure to open/failure to show error

     "Microsoft jet database engine could not find object MSysDB.  Make sure the object exists and that you spell its name correctly and the path name correctly." -- 3011

     "The Microsoft Jet database engine could not find the object MSysCompactError. Make sure the object exists  and that you spell its name correctly and the path name correctly"

     "The Microsoft Jet database engine could not find the object 'databases'. Make sure the object exists and that you spell its name and path name correctly."

     "The Microsoft Jet database engine could not find the object 'filename'. Make sure the object exists and that you spell its name and the path name correctly. "  

     "Invalid field data type" -- 3259

     "Record(s) can't be read, no read permissions on 'database.mdb'"  -- 3112

     "Could not find field 'xxx'" -- 1017

     "Invalid Bookmark" -- 3159

     This database is in an unrecognized format. The database may have been created with a later version of Microsoft Access than the one you are using. Upgrade your version of Microsoft Access to the current one, then open this database. -- 3343

     "You cannot carry out this action at the present time" -- 2486

     "Record is deleted"

     "The database has been placed in a state by user 'xxx' on machine 'mmm' that prevents it from being opened or locked" -- 3704

     "Needs to be repaired" and "Not a valid password"  (after repairing) -- 2239

     "The database has been placed in an unexpected state." or "This database is in an unexpected state; Microsoft Access can't open it."
    "This database is in an unexpected state; Microsoft Access can't open it..  The database has been converted from a prior version of Microsoft Access by using the DOA compact database method instead of the convert database command on the tools menu. This has left the database in an unconverted state."
    "This database is in an unexpected state; Microsoft Access can't open it. This database has been converted from a prior version of Microsoft Access by using the DAO CompactDatabase method instead of the Convert Database command on the Tools menu (Database Utilities submenu).  This has left the database in a partially converted state. If you have a copy of the database in its original format, use the Convert Database command on the Tools menu (Database Utilities submenu) to convert it.  IF the original database is no longer available, create a new database and import your tables and queries to preserve your data.  Your other database objects can't be recovered."
    -- 2573

     "Disk Error -- Reserved error (-1601)" --3000

     "Table 'TempMSysAccessObjects' already exists."

     "Record(s) cannot be read; no read permission on 'MSysAccessObjects'" or Record(s) cannot be read; no read permission on 'MSysACEs'. -- 3112

     "The Microsoft Jet database engine cannot find the input table or query 'MSysAccessObjects'. Make sure it exists and that its name is spelled correctly." -- 3078

     "Could not use <name>; file already in use. (Error 3045) The specified file is currently being used by another user or session. Wait for the other user or session to finish working with the file, and then try the operation again." -- 3045

     "Operation invalid without current index" -- 3019

     "'database.mdb' isn't an index in this table. Look in the Indexes collection of the TableDef object to determine the valid index names." -- 3015

     "disk or network error" -- 3043

     "Unspecified Error"  

     "The instruction at "0x11111111" referenced memory at "0x22222222". The memory could not be "written"

     The Visual Basic for Applications project in the database is corrupt.

     Error accessing file. Network connection may have been lost. or "This action will reset the current code in break mode."-- 304548

     "Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience."

     "AOIndex is not an index in this table".

    Jet compact utility.
    The Jetutils.exe file contains the following files:
       Jetlock.doc           Understanding Microsoft Jet Locking White Paper
       Readme.txt            Readme file with Installation information
       LDBView.exe           LDBView utility
       Dblck.exe             Self-extracting executable that contains the setup files for DBLock
       Msldbusr.exe          Self-extracting executable that contains Msldbusr.dll and associated files.
      Jet UserRoster
    Check who is logged into a database.
      Remove Access Security
    Remove Security Settings from an access database.

     Click here for recovery services


    Typical Causes of MDB File Corruption
    There are three main causes of corruption in Access/Jet mdb files.
    Database is Suspect/Corrupted Due to Interrupted Write Operation
    You should always quit Access properly by clicking Exit or Close on the File menu. If a database is open and writing data when Access is abnormally shut down, the Jet database engine may mark the file as suspect/corrupted. This can happen if the computer is manually turned off without first shutting down Windows or if power is lost. Other situations may not shut down Access but may still interfere with Jet's writing of data to the disk while the database is open. This can happen, for instance when networks experience data collisions or disk drives malfunction. If any of these interruptions occur, then Jet may mark the database as potentially corrupted.

    When Jet begins a write operation, it sets a flag, and resets the flag when the operation is completed. If a write operation is interrupted, the flag remains set. When you try to open that database again, Jet determines that the flag is set and reports that the database is corrupted. In most cases, the data in the database is not actually corrupted, but the set flag alerts Jet that corruption may have occurred. In cases such as this, compacting and/or repairing the database can typically restore the database. Fortunately, there are ways to determine which user and workstation was responsible for marking the file as suspect. See the "How to Determine What Users/Workstations Are Causing the File to be Marked Suspect" section later in this article.
    Faulty Networking Hardware
    In this case, the file corruption does not involve the Jet database engine; rather the file is literally corrupted by some outside cause. The cause can be one or more links in the hardware chain between the computer that the database resides on and the computer that has the database open. This list includes, but is not limited to, network interface cards, network cabling, routers, and hubs.

    Hardware-based corruption is typically indicated by .mdb files that cannot be restored through the use of compacting, repairing, or Jetcomp. Hardware corruption will typically recur until the responsible hardware is repaired or replaced.
    Opening and Saving the MDB File in Another Program
    There is no way to recover a .mdb file that was opened and then saved in a program other than Access. For example, Microsoft Word allows you to open an Access database and then save it (although it serves no good purpose to do so because if you open an MDB file in another program, all you can see are extended characters). Saving the file in this manner will cause the .mdb file to prompt you for a database password when you try to open it in Access even though the file may have never been password-protected in Access. The password prompt occurs in such cases because the first byte range that Access checks when it opens a file is where the database password would be. If that byte contains corrupted data, Access treats the file as being password protected. Even if there were a way to get around the password prompt in this case, the database would still be unrecoverable because the binary structure is scrambled and therefore unreadable to Access. Recovering a backup copy of the file is the only solution in this case. For additional information about this issue, click the article number below to view the article in the Microsoft Knowledge Base:
    223043 ACC: Database Password Appears Even Though It Was Never Set

    How to Determine What Users/Workstations Are Causing the File to Be Marked Suspect
    You can determine which workstation and user caused Jet to mark a .mdb file as suspect with the LDBView utility, which is available by downloading Jetutils.exe from the following Microsoft Web site:

    For additional information about the Microsoft Jet Utilities, click the article number below to view the article in the Microsoft Knowledge Base:
    176670 ACC: Microsoft Jet Utilities Available in Download Center

    Ldbview let you observe which users are currently logged into the database, as well as any users that may have left the file in a suspect state.
    Steps That You Can Take to Help Prevent Corruption
    Avoid losing power during database writes. Losing power can cause the database to be left in a suspect state.
    Avoid dropping network connections.
    Avoid abnormal termination of Microsoft Jet connections such as power loss, manual shutdown, having Task Manager shutdown the application, and so on.
    When programming, close all Data Access Object (DAO) and ActiveX Data Objects (ADO) objects that you have open. Examples include Recordset, QueryDef, TableDef, and Database objects.

    Fatal system errors almost always cause abnormal termination. If your database is prone to fatal errors, you should resolve the errors before the database becomes too damaged to open or recover.For additional information about the Microsoft Jet Utilities, click the article number below to view the article in the Microsoft Knowledge Base:
    148424 ACC: Troubleshooting Fatal System Errors in Microsoft Access 95 and Microsoft Access 97

    Compact the database often.

    IMPORTANT: Do not run the Repair Database command in Access 97 unless Microsoft Jet prompts you to do so.
    Do not run IPX on Windows NT Server where Jet databases are located across the network and the client is Microsoft Windows 95 with IPX/SPX. Instead, run TCP-IP on the Windows NT Server and a dual protocol stack of IPX and TCP-IP on the Windows 95 client. Windows NT to Windows NT with IPX/SPX will not cause the problem, nor will Novell to any client.
    Avoid a large number of open and close operations in a loop (40,000 successive open/close operations to over 1,000,000.
    Accessrecovery, MDB,access,password,crack,msaccess,recovery,office,access2,access2002,access2000,
    development,security,probelms,help with,protection,problems,software,tools,access, repair,access, mdb,
    datenbank, database, reparatur, reparieren, defekt, kaputt, recover, recovery, restore, repair, tool,
    utility, 2.0, 95, 97, 2000, a97, 8.0, a2k, crash, wiederherstellen, damaged, demaged, unbekanntes, format,
    corrupt, retten, daten, tabellen, rettung, defekte access datenbank, access repair, access-rettung,
    access-repair, mdb-repair, kaputte datenbank, outlook, express, pst,fix dbx,

    Author Comment

    And the kitchen sink is probably in there as well.

    I'll start dissecting this bit by bit but there's certainly enough info there to create what I'm looking for.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now