Solved

Compact Repair:  revision for open database

Posted on 2007-11-19
3
196 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

16 Experts available now in Live!

Get 1:1 Help Now