Thursday, March 30, 2006

SnTT: Compact Local Databases on Demand

A couple of weeks ago, Chris Miller posted a tip about scheduling databases to be compacted on a user workstation. If, for whatever reason, you don't want to schedule that task, here is some code you can put in a user-accessible button (like in a "Procedures Manual" document) that compacts databases and sends a mail message to the user with the results.

Dim session As New NotesSession
Dim db As NotesDatabase
Dim dbdir As New NotesDBDirectory("")
Dim Stat As Long
Dim nlog As New NotesLog("Compact Utility")

Call nlog.OpenMailLog(session.username,"DB Compact Utility")

Set db = dbdir.GetFirstDatabase(Database)
Call db.Open("",db.Filepath)
On Error Resume Next
While Not (db Is Nothing)
Print "Compacting: " & db.FilePath
If db.PercentUsed < 90 Then
stat = db.Compact
If Err = 4005 Then
Call nlog.LogAction(db.FilePath & " is in use or not on workspace.")
Err = 0
Else
Call nlog.LogAction("Compacted " & db.FilePath & " bytes freed: " & Str(stat))
End If
Else
Call nlog.LogAction("Database " & db.FilePath & " already " & db.PercentUsed & " percent in use")
End If
Call db.Close()
Set db = dbdir.GetNextDatabase()
Call db.Open("",db.filepath)
Wend
C
all nlog.Close
Messagebox("Finished Compacting")

This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.



Technorati tags:
Categories: Show-n-Tell Thursday_

1 comment:

Chris Miller said...

Very nice Don. Glad to see someone take it a step further.

This could be a toolbar icon too I am thinking for someone else that just asked about pushing it out.