2

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
Baku Bakar
  • 442
  • 2
  • 8
  • 20

1 Answers1

1

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.

Tode
  • 11,795
  • 18
  • 34
  • Todoe thank you very much. In your first suggestion, what is Software_Server? Is this the mailserver, that it is running? Secondly, is it possible to delete a maildatabse which is located on a different domino server than the agent/lotus script is running? – Baku Bakar Sep 07 '22 at 15:16
  • 1
    Software_Server is just a sample server name. You would substitute your own. It should be the server that is configured as the Administration Server for your mail database. You can find the Administration Server by using NotesDatabase.ACL,AdministrationServer. – Richard Schwartz Sep 07 '22 at 17:46
  • hi @RichardSchwartz thank you very much. It worked with NotesAdministrationProcess. There is only one issue / open point: In admin4.nsf it asks me for manual approval. Any chance to skip that and delete it directly? – Baku Bakar Sep 15 '22 at 13:04
  • Did you read the linked documentation? Try Using "ApproveReplicaDeletion"... – Tode Sep 15 '22 at 13:49
  • @Tode I use your first suggested code. And I did. The documentation is telling me "The note ID of the entry pending approval." I add after 'noteid$ = adminp.DeleteReplicas("Software_Server", "Guys1")' this line adminp.Approvereplicadeletion(noteid$)', but input is incorrect. From where I know the noteid of the pending approval, from the user that i recently DeleteReplicas created? – Baku Bakar Jan 19 '23 at 11:02