Solved

Compact Repair:  revision for open database

Posted on 2007-11-19
3
206 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:fordraiders
  • 2
3 Comments
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20314114
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.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 20314433
is there a way to close the database if it is open ?

Or is there an error trap ?
0
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 500 total points
ID: 20314925
If it's not your program that has it open, then you can't.  You can use simple try/catch blocks to catch the error.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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