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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compressing a DB programitcally 1

Status
Not open for further replies.

hitechboy78737

Programmer
Nov 8, 2004
82
US
In VB6, compressing a database from code was pretty easy. I cannot, however, seem to find any reference on this in .net. I'm sure that it's there... but by golly it's buried in the mass of info and I can't seem to mine it out. It seems that the vb6 and .net routines to do this are not compatable.

Under vb.net, how do you compress a database from the application.
 
Hey,

You cant compact a db while in it but apart from that it is pretty straightforward. Here is a function of mine that I use to compact dbs in a target folder.


Public Function CompactDB(ByVal dirPath As String) As Integer
'Compacts all databases in given dir

Dim S As Variant
Dim je As New JRO.JetEngine
Dim fso As FileSystemObject
Dim fsoFolder As Folder
Dim fsoFile, tempFile As File
Dim tempName As String

'Make a new File System object.
Set fso = New FileSystemObject
' Get the FSO Folder (directory) object.
If Len(Dir(dirPath)) Then
Set fsoFolder = fso.GetFolder(dirPath)

For Each fsoFile In fsoFolder.Files
If Right(fsoFile.Name, 4) = ".mdb" Then
je.CompactDatabase _
SourceConnection:="Data Source=" & dirPath & "\" & fsoFile.Name, _
DestConnection:="Data Source=" & dirPath & fsoFile.Name & "temp.mdb; "
tempName = fsoFile.Name
fsoFile.Delete
Name (dirPath & tempName & "temp.mdb") As (dirPath & tempName)
End If
Next fsoFile
CompactDB = 0
Else
MsgBox "Invalid Path"
CompactDB = -1
End If

Set fso = Nothing
Set fsoFolder = Nothing
End Function


Mordja

 
Thank you Mordja! Exactally what I was looking for. A star for you!!

Kevin Howell
 
Well... this is probably a stupid question... but-

what namespace does jro.jetengine and filesystemobject reside?
 

You need the Microsoft Jet and Replication Objects (2.6) Library and the Microsoft Scripting Runtime library

Tools - References etc

Mordja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top