2

是否可以通过代码以编程方式(从 .NET 例如通过 SQL 查询)询问 Access 数据库是否已损坏或是否有包含损坏行的表?

//安迪

4

3 回答 3

2

None of the application/database level objects have such an "isCorrupted" property.

Furthermore, corrupted databases do not have a standard behaviour. Depending on the situation, database might not open at all (file is not recognized as a valid mdb file). If it opens, error might occur immediately or when using/opening a specific object (table, form, or VBA code).

In these conditions, I do not think there is a positive answer to your question.

Note: In addition to the standard compact/repair option of Access, exporting object to other databases (or importing them from the corrupted database) as well as the non-documented .saveAsText command can be of great help.

于 2008-10-28T22:08:41.953 回答
0

我们的网络问题导致共享驱动器上的访问数据库损坏,我花了很多时间从几个特定的​​表中清理损坏的行。

尤其是备注字段是损坏的一个很好的指示,因为它们不像其他数据那样内联存储,而是保存在单独的表中。我可以在数据表模式下打开损坏的表,并尝试通过将焦点放在损坏的备注单元格上来确定哪些行已损坏——如果有损坏,我会立即收到错误消息。

损坏的 Int 和 Date 列会有奇数值(3/18/1890、-11100910 等),但当我读取它们的值时实际上不会抛出任何错误。

这就是为什么循环遍历数据库中的所有记录和字段的原因,如先前答案中的 VBA 所示,是有道理的,但只有在备忘录字段损坏时才能最可靠地执行。

于 2009-04-15T13:32:32.163 回答
0

下面是一些 VBA,可用于检查以前版本的 Access 中的错误。它也可能适合 2007 年。

Sub CheckForErr(tablename)
Dim rs As dao.Recordset
Dim db As Database

Set db = CurrentDb

Set rs = db.OpenRecordset(tname)

With rs
   Do While Not .EOF
        For Each fld In rs.Fields
            If IsError(rs(fld.Name)) Then
               Debug.Print "Error"
            End If
        Next
        .MoveNext
    Loop
End With

rs.Close
Set rs = Nothing

End Sub
于 2008-10-28T21:21:55.277 回答