Solved

Compact Repair:  revision for open database

Posted on 2007-11-19
3
184 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

8 Experts available now in Live!

Get 1:1 Help Now