Solved

Compact Repair:  revision for open database

Posted on 2007-11-19
3
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 1 month apart 11 38
vb.net and creating a class 5 29
Optimize the query 5 50
vb.net IF Statement not working in Code Behind with Request.ServerVariables (It used to) 2 55
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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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