943,559 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 6884
  • VB.NET RSS
Jun 2nd, 2006
0

Repair Access database

Expand Post »
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:

VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
cpopham is offline Offline
65 posts
since Mar 2005
Aug 16th, 2006
0

Re: Repair Access database

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


Reputation Points: 10
Solved Threads: 0
Newbie Poster
recoveryguru is offline Offline
1 posts
since Aug 2006
May 2nd, 2008
0

Re: Repair Access database

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
fyz
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fyz is offline Offline
9 posts
since Apr 2008
May 28th, 2008
0

Re: Repair Access database

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Steal32 is offline Offline
9 posts
since Apr 2008
Jul 31st, 2009
0

Re: Repair Access database

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Davidpoul is offline Offline
9 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to connect to oracle 11g
Next Thread in VB.NET Forum Timeline: Displaying Excel worksheet cell data in an inputbox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC