Reputation: 462
I would like to delete a mail database over a notes agent. Sometimes the mail databases have a replica.
Whats the best way to delete the mail file itself and also all other replicas (if they exist)? My code below looks like this, but it doesn't delete the mail file in a replica.
Dim mailfile As String
mailfile = "mail\doe.nsf"
Dim db As New NotesDatabase("", mailfile)
If db.IsOpen Then
'Mark to delete it later
Call db.MarkForDelete()
Else
'Delete now
Call db.Remove
End If
Upvotes: 2
Views: 635
Reputation: 12080
You could use the built in function to do this by using NotesAdministrationProcess:
Sub Initialize
Dim session As New NotesSession
Dim adminp As NotesAdministrationProcess
Set adminp = _
session.CreateAdministrationProcess("Software_Server")
noteid$ = adminp.DeleteReplicas("Software_Server", "Guys1")
'- in case you want to open the generated adminp request
If noteid$ <> "" Then
Dim db As New NotesDatabase("Software_Server", "admin4")
Dim ws As New NotesUIWorkspace
Call ws.EditDocument(False, db.GetDocumentByID(noteid$))
End If
End Sub
If you do not want to wait for this (as it needs time: replicate admin4.nsf to all servers, execute admin process there, replicate back...), you can do this by yourself if you know the servers where the replicas are in advance:
Dim mailfile As String
mailfile = "mail\doe.nsf"
Dim otherServers(2) as String
Dim replicaID as String
Dim db as NotesDatabase
otherServers(0) = "FirstServerName/Certifier"
otherServers(1) = "SecondServerName/Certifier"
otherServers(2) = "ThirdServerName/Certifier"
Set db = New NotesDatabase("PrimaryServer/Certifier", mailfile)
If db.IsOpen Then
replicaID = db.ReplicaID
On Error Goto ErrorRemove
'Delete now
Call db.Remove
On Error Goto ErrorHandler
Forall serverName in otherServers
Set db = New NotesDatabase("", "")
Call db.OpenByReplicaID( serverName, replicaID )
If db.IsOpen Then
On Error Goto ErrorRemove
'Delete now
Call db.Remove
On Error Goto ErrorHandler
End If
End Forall
End If
EndOfRoutine:
Exit Sub
ErrorRemove:
Call db.MarkForDelete()
Resume Next
ErrorHandler:
'- do usual error handling here
REMARK: Your check for "db.IsOpen" does not help at all. As "IsOpen" does NOT return if a database is currently open somewhere. It returns, if YOUR SCRIPT was able to open the database at exaxtly that moment... I added an error handler to take this into account.
Upvotes: 1