[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Compressing Access-95 table thru VB.NET


Hi,
Question1.
   Using VB.NET( or C#) , how can I compress an Access-95 table ?
 (This can be considered as a windows application. But ultimately, this EXE  has to be in a schedule that is run once in a week).

Question2.
  Actually there is a windows service running in the back which  , in every 10 minutes deletes almost all rows in the  Access table (same table which has to be compressed once in a week) . Do we have to do anything additionally, considering the possibility that  the  EXE in the schedule will run to compress the table at the same time when the windows service is deleting the rows in the table?  
                                   
                                        Thanking you
0
sgs1970
Asked:
sgs1970
2 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
You still have to use DAO or ADO because .Net does not gives you this feature.

See http://www.knowdotnet.com/articles/compactmdb.html
0
 
iboutchkineCommented:
Add ref to Microsoft Jet replication Objects lib
Jet OLEDB:Engine Type = 4 - for Access97
Jet OLEDB:Engine Type = 5 - fro Access 2000
============================================


Imports System.IO.File


  Private Sub CompactDatabase()
        Dim jro As New JRO.JetEngine
        Dim sConnSource As String
        Dim sConnDestination As String

        'compact db to temp.mdb

        sConnSource = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & DBPATH & ";Jet OLEDB:Engine Type = 4"

        sConnDestination = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & DBPATHONLY & "temp.mdb;Jet OLEDB:Engine Type = 4"

        Try
            jro.CompactDatabase(sConnSource, sConnDestination)
            Delete(DBPATH) 'delete db(System.IO.FIle)
            Copy(DBPATHONLY & "temp.mdb", DBPATHONLY & "CheckRec.mdb")
            Delete(DBPATHONLY & "temp.mdb")
        Catch
            MessageBox.Show("Cannot compact database. It might be open by another user.", "Error Compacting", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
========================================================

another example


Sub Main()

        Dim jro As JRO.JetEngine

        jro = New JRO.JetEngine()

        jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\nwind.mdb", _
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\NewNwind.mdb;Jet OLEDB:Engine Type=4")

        MsgBox("Finished Compacting Database!")
End Sub

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now