Wabbit-
Not sure of your programming preference, but if you care for VB.NET, take a look here:
http://support.microsoft...spx?scid=kb;en-us;306287Here is a rudimentary example... of course, it could be a lot more detailed ;-)
Cleaning the database tables can be accomplished using the OleDbCommandBuilder function with an SQL command such as "DELETE * FROM AnalysisEvents". Honestly, I omitted this function, because these tables have dependencies upon other tables. I'm not quite sure of the proper sequence to clean them (i.e., remove entries). For example, the AnalysisEvents table is dependent upon the Analysis table. If I understood the relationship better, I could easily add the code. I included some of my coding thoughts as a text file within the attached solution file.
[code:1:75ea3a92de]' Add Reference to Microsoft Jet and Replication Objects 2.x Library
Imports System.Data.OleDb
Imports System.IO
Public Class frmUtility
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code " ******* Omitted from post due to length of post constrints *******
#End Region
Private mdbFile1 As String = "C:\\Program Files\\Equis\\MetaStock\\ST_DATA.MDB"
Private mdbFile2 As String = "C:\\Program Files\\Equis\\MetaStock\\ST_DATA_BU.MDB"
Private mdbFile3 As String = "C:\\Program Files\\Equis\\MetaStock\\ST_DATA_TEMP.MDB"
Private Sub BackupDB()
Try
Dim file As IO.File
Select Case file.Exists(mdbFile1)
Case True
' Make a backup copy (overwrite existing backup, if any)
file.Copy(mdbFile1, mdbFile2, True)
Case False
' File not found
MessageBox.Show("File not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
Catch ex As Exception
' Unexpected error
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub CompactDB()
' Attempting to compact a database file that is currently in use will result in an exception
Try
Dim file As IO.File
If file.Exists(mdbFile3) Then
' Delete temporary file, if exists
file.Delete(mdbFile3)
End If
' Create a new compacted file
Dim jro As New JRO.JetEngine
jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile1, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile3 + ";Jet OLEDB:Engine Type=5")
' Overwrite original file with compacted file
file.Copy(mdbFile3, mdbFile1, True)
' Delete temporary file
file.Delete(mdbFile3)
Catch ex As Exception
' Unexpected error
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnManage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManage.Click
lblStatus.Text = "Working..."
If cbCompact.Checked = True Then
CompactDB()
' Status report
lblStatus.Text = "Compacting..."
End If
If cbBackup.Checked = True Then
BackupDB()
' Status report
lblStatus.Text = "Backup in progress..."
End If
Beep()
lblStatus.Text = ""
cbCompact.Checked = False
cbBackup.Checked = False
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
MyBase.Close()
End Sub
Private Sub cbCompact_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCompact.CheckedChanged
If cbCompact.Checked = False And cbBackup.Checked = False Then
btnManage.Enabled = False
Else
btnManage.Enabled = True
End If
End Sub
Private Sub cbBackup_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbBackup.CheckedChanged
If cbCompact.Checked = False And cbBackup.Checked = False Then
btnManage.Enabled = False
Else
btnManage.Enabled = True
End If
End Sub
End Class[/code:1:75ea3a92de]