Repair Access database

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 65
Reputation: cpopham is an unknown quantity at this point 
Solved Threads: 0
cpopham cpopham is offline Offline
Junior Poster in Training

Repair Access database

 
0
  #1
Jun 2nd, 2006
Here is one that is stumping me.

I have an Access 2000 database backend. It got corrupted. It is a large database. I compacted and repaired it and a record came up corrupted. There was a compact error table created that has a binary column in it. The binary column points to a bookmark that tells which row was corrupted. I am trying use vb .net to retrieve that row using the binary column to show me which record is corrupted, however, I cannot get it to work right. I have found VBA for Access code that does something similar, but I need it in VB .net. Here is the VBA code that I have:

  1. Sub main()
  2. On Error GoTo ErrorHandler
  3. Dim db As DAO.Database, vBookMark As Variant, _
  4. rsMSysCompactError As DAO.Recordset, strErrorTable As String, _
  5. rsErrorTable As DAO.Recordset, fldErrorField As DAO.Field, _
  6. strSQLSEL As String, strColumnValue As Variant, _
  7. qdTemp As QueryDef, strSQLINS As String, intLoop As Integer, _
  8. lngTableNameLength As Long, _
  9. colErrorCollection As New Collection, intErrorCount As Integer
  10.  
  11. Set db = CurrentDb()
  12. ' Walk through the MSysCompactError table to find rows that reflect
  13. ' lost data values.
  14. Set rsMSysCompactError = db.OpenRecordset("SELECT * FROM MSysCompactError WHERE ErrorRecId IS NOT NULL", dbOpenDynaset)
  15. intErrorCount = 0
  16. While Not rsMSysCompactError.EOF
  17. ' Get the name of the table that had column data missing.
  18. strErrorTable = rsMSysCompactError!ErrorTable
  19. ' Check to see that tablename is not greater than 48 characters
  20. ' to stay under 64 character tablename limit.
  21. lngTableNameLength = Len(strErrorTable)
  22. If lngTableNameLength > 48 Then
  23. strErrorTable = Mid(strErrorTable, 1, 48)
  24. ' See if this truncated table name already exists.
  25. On Error Resume Next
  26. colErrorCollection.Add strErrorTable, strErrorTable
  27. ' If this already exists in the collection, then there is a
  28. ' duplicate table name.
  29. If Err = 457 Then
  30. ' Truncate one more digit to append on the intErrorCount
  31. ' number to eliminate the duplicate table name.
  32. strErrorTable = Mid(strErrorTable, 1, 47)
  33. strErrorTable = strErrorTable & Mid((Str(intErrorCount)), 2, 1)
  34. intErrorCount = (intErrorCount + 1)
  35. End If
  36. End If
  37.  
  38. ' Get the bookmark value of the row that had lost column data.
  39. vBookMark = rsMSysCompactError!ErrorRecId
  40. ' Open table that has lost column data.
  41. Set rsErrorTable = db.OpenRecordset(strErrorTable, dbOpenTable, dbReadOnly)
  42. ' Move to row that has lost column data.
  43. rsErrorTable.Bookmark = vBookMark
  44. ' Start to build SQL string to call up in a table window.
  45. strSQLSEL = "SELECT * INTO MSysCompactError" & strErrorTable & " FROM " & strErrorTable & " WHERE "
  46. strSQLINS = "INSERT INTO MSysCompactError" & strErrorTable & " SELECT * FROM " & strErrorTable & " WHERE "
  47. intLoop = 0
  48. For Each fldErrorField In rsErrorTable.Fields
  49. strColumnValue = fldErrorField.Value
  50. ' Logic to build predicate based on various data types.
  51. If Not IsNull(strColumnValue) Then
  52. ' Can't use ordinal as no guarantee of first column
  53. ' being zero.
  54. ' Check to see if this is the first column or not to
  55. ' build SQL statement.
  56. If intLoop = 0 Then
  57. If fldErrorField.Type = dbDate Then
  58. strSQLSEL = strSQLSEL & "[" & fldErrorField.Name & "] = " & "#" & strColumnValue & "#"
  59. strSQLINS = strSQLINS & "[" & fldErrorField.Name & "] = " & "#" & strColumnValue & "#"
  60. Else
  61. If fldErrorField.Type = dbText Or fldErrorField.Type = dbChar Or fldErrorField.Type = dbMemo Then
  62. strSQLSEL = strSQLSEL & "[" & fldErrorField.Name & "] = " & "'" & strColumnValue & "'"
  63. strSQLINS = strSQLINS & "[" & fldErrorField.Name & "] = " & "'" & strColumnValue & "'"
  64. Else
  65. strSQLSEL = strSQLSEL & "[" & fldErrorField.Name & "] = " & strColumnValue
  66. strSQLINS = strSQLINS & "[" & fldErrorField.Name & "] = " & strColumnValue
  67. End If
  68. End If
  69. Else
  70. If fldErrorField.Type = dbDate Then
  71. strSQLSEL = strSQLSEL & " AND " & "[" & fldErrorField.Name & "] = " & "#" & strColumnValue & "#"
  72. strSQLINS = strSQLINS & " AND " & "[" & fldErrorField.Name & "] = " & "#" & strColumnValue & "#"
  73. Else
  74. If fldErrorField.Type = dbText Or fldErrorField.Type = dbChar Or fldErrorField.Type = dbMemo Then
  75. strSQLSEL = strSQLSEL & " AND " & "[" & fldErrorField.Name & "] = " & "'" & strColumnValue & "'"
  76. strSQLINS = strSQLINS & " AND " & "[" & fldErrorField.Name & "] = " & "'" & strColumnValue & "'"
  77. Else
  78. strSQLSEL = strSQLSEL & " AND " & "[" & fldErrorField.Name & "] = " & strColumnValue
  79. strSQLINS = strSQLINS & " AND " & "[" & fldErrorField.Name & "] = " & strColumnValue
  80. End If
  81. End If
  82. End If
  83. End If
  84. intLoop = (intLoop + 1)
  85. ' QJet limitation for maximum conditions is reached.
  86. If intLoop = 39 Then
  87. Exit For
  88. End If
  89. Next fldErrorField
  90. On Error Resume Next
  91. ' Create error table if it does not exist.
  92. db.Execute strSQLSEL, dbFailOnError
  93. If Err = 3010 Then
  94. On Error GoTo ErrorHandler
  95. ' Add rows to error table if it already exists.
  96. db.Execute strSQLINS, dbFailOnError
  97. End If
  98. rsErrorTable.Close
  99. rsMSysCompactError.MoveNext
  100. Wend
  101. rsMSysCompactError.Close
  102. MsgBox "Done!"
  103. Exit Sub
  104. ErrorHandler:
  105. MsgBox "An error has occurred " & Err & " " & Error
  106. Resume Next
  107. End Sub

Any ideas?
Thanks, Chester
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 1
Reputation: recoveryguru is an unknown quantity at this point 
Solved Threads: 0
recoveryguru recoveryguru is offline Offline
Newbie Poster

Re: Repair Access database

 
0
  #2
Aug 16th, 2006
If you access database gets corrupted try easy ways to repair rather using long codes. You can use Kernel Access Repair Software as it repair corrupted access database
http://www.nucleustechnologies.com/A...r-Software.php


Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: fyz is an unknown quantity at this point 
Solved Threads: 0
fyz fyz is offline Offline
Newbie Poster

Re: Repair Access database

 
0
  #3
May 2nd, 2008
Hi,

There is a tool called Advanced Access Repair. I have used it to repair many corrupt Access MDB files on my damaged disks successfully.

Hope this helps.

Alan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: Steal32 is an unknown quantity at this point 
Solved Threads: 0
Steal32 Steal32 is offline Offline
Newbie Poster

Re: Repair Access database

 
0
  #4
May 28th, 2008
In case of database corruption you can import your corrupted databse to a new blank database or you can repair it using compact and repair utility provided by MS office. This tool will repair your damaged database. In case its not able to repair database then you search for access repair utility.
Last edited by Narue; May 30th, 2008 at 11:59 am. Reason: Snipped advertising
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 7
Reputation: Davidpoul is an unknown quantity at this point 
Solved Threads: 0
Davidpoul Davidpoul is offline Offline
Newbie Poster

Re: Repair Access database

 
0
  #5
Jul 31st, 2009
If your access database get corrupted then try Stellar Phoenix Access Recovery Software. I used it to repair my corrupt Access MDB files and it successfully repair and recover all my data.
Last edited by Davidpoul; Jul 31st, 2009 at 9:23 am.
David Poul
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC