Solved

Getting error compacting an Access Database

Posted on 2002-05-24
17
351 Views
Last Modified: 2013-12-25
When I call the CompactAndRepairDB function in the code below, I get the following error:

Err.Number = -2147467259
Err.Description = Could not find installable ISAM.

What could be the problem? How can I resolve it? My project references the JRO engine. Similar code using the DAO engine works fine.
----------
Code
==========

Private mvarConn As ADODB.Connection   'local copy

Public Function CompactAndRepairDB(ByVal sDBName As String, Optional ByVal sPassword As String) As Boolean
  Dim OJE As New JRO.JetEngine

  On Error GoTo CompressErr
  CompactAndRepairDB = True
  ' Close the database & workstation first
  CloseDB
  DoEvents

  ' Compact and repair the database
  OJE.CompactDatabase _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & AppPath & sDBName & ";Jet OLEDB:Database Password=" & sPassword & ";", _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & AppPath & Split(sDBName, ".")(0) & _
    ".bk!;Jet OLEDB:Database Password=" & sPassword & ";Jet OLEDB:Encrypt Database=True;"
  Set OJE = Nothing
  MkDir AppPath & "Backup"
  Kill AppPath & "Backup\" & Split(sDBName, ".")(0) & ".bak"
  Name AppPath & sDBName As AppPath & "Backup\" & Split(sDBName, ".")(0) & ".bak"
  DoEvents
  Name AppPath & Split(sDBName, ".")(0) & ".bk!" As AppPath & sDBName
  DoEvents
  ConnectDB sDBName, sPassword
  Exit Function
CompressErr:
  CompactAndRepairDB = False
  Select Case Err.Number
    Case 53, 75
      Err.Clear
      Resume Next
    Case Else
      MsgBox "Backup error " & Err.Number & ": " & Err.Description, vbCritical
      ConnectDB sDBName, sPassword
      Set OJE = Nothing
      Exit Function
  End Select
End Function

Public Function ConnectDB(ByVal sDBName As String, Optional ByRef sPassword As String) As Boolean
  Dim StrConn As String
  'Procedure to Connect a Valid DataSource
  On Error GoTo LocalErr
    Screen.MousePointer = vbHourglass
    StrConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppPath & sDBName & "; Jet OLEDB:Database Password=" & sPassword & ";"
    If Dir(AppPath & Split(sDBName, ".")(0) & ".ldb", vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem) <> "" Then
      MsgBox "The Server was not properly shut down last time or" & vbCrLf & _
        "another application is using it's data file(s). " & vbCrLf & vbCrLf & _
        "To avoid corruption of data always use the Exit command on " & vbCrLf & _
        "the File menu to shut down the application.", vbExclamation, "Server"
    End If
    Set mvarConn = New ADODB.Connection
    mvarConn.CursorLocation = adUseClient
    mvarConn.ConnectionTimeout = 120
    mvarConn.Open StrConn
    Screen.MousePointer = vbDefault
    ConnectDB = True
    Exit Function
LocalErr:
    Screen.MousePointer = vbDefault
    MsgBox Err.Description
End Function

Public Function CloseDB() As Boolean
  On Error GoTo LocalErr
  If Not mvarConn Is Nothing Then
    mvarConn.Close
    DoEvents
    Set mvarConn = Nothing
  End If
  CloseDB = True
  Exit Function
LocalErr:
End Function
0
Comment
Question by:bmatumbura
17 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7032990
try installing "Microsoft Jet 4.0 Service Pack 3" available at http://www.microsoft.com/data/download_Jet4SP3.htm
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7033346
Take a look at this article:

HOWTO: Compact Microsoft Access Database via ADO (Q230501)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q230501&SD=MSKB&

Notice that they use two backslashes (\\) in the path.

Anthony
0
 
LVL 3

Expert Comment

by:vbbuff
ID: 7034965
dear bmatumbura,

I think that you can use the jro objects compactdatabase method without an error only if you have compacted that database previously through Microsoft Access.

Open Microsoft Access & then select tools, Database Utilities, Compact & RepairDatabase. Select your database & compact it.

Once you have compacted it, You try compacting your Database through your code. I think your code will work.



0
 
LVL 18

Expert Comment

by:mdougan
ID: 7051135
You can get this error message if you do not have the version of the jet oledb installed on your machine that you are referencing in your connect statement.

Run Regedit.exe and do a search on (allowing partial matches):

"Microsoft.Jet.OLEDB"

Check to see if you have a version 4.0 installed.  If you do, then you should hit a match like:

Microsoft.Jet.OLEDB.4.0

If not, then download and install MDAC_TYP.EXE version 2.5 or above.
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 7095588
I tried all this but I am still getting the same error message. Even on another computer that has MDAC_Type 2.5 Installed. What could be the error in my CompactAndRepairDB routine? Could it be because the database is password protected?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7095602
Have you installed "Microsoft Jet 4.0 Service Pack 3" (see previous post for the link).
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 7100424
Got errors while installing Jet 4.0 SP3. Error registering one of the odbc dll s, and setup would quit. My computer has Windows 2000 Server running SQL Server & IIS.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7100919
are you logged as administrator while installing?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7100920
what is the exact wording of the error?
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 7104163
Will post the actual error message tomorrow.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7128877
Any progress?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7297446
This question appears to be abandoned. A question regarding it will be left in the CleanUp
area; if you have any comment about the question, please leave it here.

Unless there is objection or further activity, one of the moderators will be asked to accept the comment
of <emoreau>.

The link to the Community Support area is:
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

DO NOT ACCEPT THIS COMMENT AS AN ANSWER.
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 7301853
Failed to make it work. Can someone e-mail me a working application that has the Compact & Repair Database function on a Password protected Access .MDB file?

My e-mail is: bmatumbura@email.com
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7301931
have you succeeded in the installation of all requirements ( "Microsoft Jet 4.0 Service Pack 3" ) ?
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 7301942
Also, be sure to be able to compact a database that doesn't have a password first. See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q230501
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 7304931
Yes. I installed the Jet SP3.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7305292
and are you able to compact a database without password?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

939 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

6 Experts available now in Live!

Get 1:1 Help Now