I have a scheduled agent which runs a command to open 2 databases and process docs from the first one into forms on the second one. When the Db runs on a schedule, the second database doesn’t open. When I run the agent manually, it opens just fine.
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim db2 As NotesDatabase
Dim doc2,doc3 As NotesDocument
Set db=sess.getdatabase("<server address>","<filepath>")
Set db2=sess.getdatabase("<server2 address>","<filepath2>")
If Not db2.Isopen Then Call db2.open("","")
Set doc3=New NotesDocument(db)
doc3.form="memo"
If Not db2.isopen Then
doc3.subject="You were right, the db won't open"
Call doc3.send(False,"Wade H Hines/Dallas/IBM")
Exit sub
End If
Added the checks for db2.isopen after diagnosing the problem…
Subject: db.getdatabase in scheduled agent not working
Hi Wade, actually, this is non-working as designed. :-)To make it work, server2 has to trust server1 before server1 is allowed to open databases on server2 from a scheduled agent. You establish this trust by editing server document on server2 and putting name of server1 to the Trusted servers field on the Security tab.
When run manually, the code works because it runs under your Notes ID, which obviously has access to server2. In scheduled agent context, however, this situation is treated differently and the server the agent runs on needs to be explicitly trusted by server the agent is trying to reach. It has to do with security and it was introduced in Domino 6.
For better explanation please see this technote: https://www-304.ibm.com/support/docview.wss?uid=swg21086111