Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

Compact Repair: revision for open database

vb.net 2003
access 2003

What I have:

Public Sub CompactAccessDBEnd(ByVal strConnectionString As String, ByVal strMDBFilename As String)
        Dim oParams As Object()
        Dim strMe As String
        If System.IO.File.Exists("C:\PROGRAM FILES\DM\CAT.MDB") Then
            strMe = FileLen("C:\PROGRAM FILES\DM\CAT.MDB")
           Dim jro As JRO.JetEngine
            jro = New JRO.JetEngine
            jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\dm\Cat.mdb", _
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\dm\Cat2.mdb;Jet OLEDB:Engine Type=5")
           System.IO.File.Delete(strMDBFilename)
            System.IO.File.Move("C:\Program Files\dm\Cat2.mdb", strMDBFilename)
            ' Clean up (Just in case)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(jro)
            jro = Nothing
            '    End If
        End If
    End Sub


What I need:
Sometimes the database cat.mdb may be open...
If it is  close it first then run the routine...

Thanks
fordraiders

Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

The downside to using access for this kind of thing is that if the database is in use by another application (or another instance of your application), you're at the mercy of that application.
Avatar of Fordraiders

ASKER

is there a way to close the database if it is open ?

Or is there an error trap ?
ASKER CERTIFIED SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial