Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repair/Compact Access database from VB.NET-code

Status
Not open for further replies.

tutuster

Programmer
Feb 2, 2005
41
FI
A: Can an app use MS Access 2003 database if there IS NOT access 2003 installed to the computer?

B: Is there a way to compact/repair an access 2003 database via vb.net code? (found some results for this, looking some other way than process.start...)

Thx in advance,
Tutuster
 
You can have an app that uses Access 2003 even if it is not installed on the computer. You'll need to make sure that Jet is installed.


In VB6, you can compact/repair an access database. You have to add a reference to ADOX to do it. I assume you can do this in vb.net also (but I don't know how). Again, google "vb.net ADOX" and see what shows up.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Yes, I've googled on this matter before posting this thread. All that was found were solutions to Visual Basic, not to the dotnet. Therefore I'd really appreciate any pointing fingers and solutions.

Thx,
Tutuster
 
Try forum796

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Issue has been solved.

In case someone else needs this kind of operation, I put the solution here.

MSDN link to this subject:
Solution:

Code:
Sub fixmdb(ByVal path As String) 'the full path to the .mdb database
        Dim i As New IO.FileInfo(path) 'to get the fileinfo for the path
        Dim file As String = i.Name 'the name of the database file
        Dim path2 As String = path.Replace(file, file + "_compacted" + i.Extension)
        ' the path where the compacted database is created

        Dim jro As New JRO.JetEngine 'new instance of the jet engine

        Try 'function compacts the DB from the ORIGINAL database to a COPY of the original
            jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path, _
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path2 + ";Jet OLEDB:Engine Type=5")
            IO.File.Copy(path2, path, True) 'the compacted DB is copied to replace (boolean TRUE if replacement is allowed) the original DB
            IO.File.Delete(path2) 'deletes the original db
        Catch ex As Exception 'any exceptions handled here
            MessageBox.Show(ex.Message)
        End Try
    End Sub

NOTE: This function needs an EXCLUSIVE access to the database
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top