Solved

Getting error compacting an Access Database

Posted on 2002-05-24
17
358 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 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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