Solved

Getting error compacting an Access Database

Posted on 2002-05-24
17
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 70

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 70

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 70

Expert Comment

by:Éric Moreau
ID: 7100919
are you logged as administrator while installing?
0
 
LVL 70

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 70

Expert Comment

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

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 70

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 70

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 70

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

726 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