LS NotesSession.getDatabase tosses "Object Variable Not Set"

  • I’ve squandered most of the day on a legacy Agent called via AJAX that inexplicably started throwing “Object Variable Not Set” on the server console. This is annoying for several reasons:
  1. There is an error handler in effect at the line that errors, yet that error handler is never triggered. Instead the error message continues to appear on the server console.

  2. I’ve done a chemo-shotgun “Rebuild All LotusScript”, without error, and without effect.

  3. I put in “Print”, which borks the AJAX horribly, but at least I can see that in Firebug. I have this code:

    Print |Initialize|

    Set ns=New NotesSession

    Set db=ns.currentDatabase

    Set lit=New Literal

    Print |- Log|

    Print | Looking for |+lit.LOGDBPATH

    If(ns Is Nothing) Then Print | No session | : Exit Sub Else Print | Platform |+ns.Platform

    Print | On |+ns.Getdatabase(ns.currentDatabase.server, “\EE\EECatsLog.nsf”).title

    Set aldb=ns.getDatabase(“”, lit.LOGDBPATH)

    Print | Current Check|

where ns, db, and lit are Agent global as NotesSession, NotesDatabase, and Literal Class respectively. That code produces this output:

Initialize

  • Log

    Looking for EE\EECatsLog.nsf

    Platform Windows/32

    On

  • What? No error on getDatabase, but no Title?? The next line, where it sets aldb without a server path, is the one that’s been “causing” the problem all along. The aldb variable is also global as NotesDatabase.

  1. Did I mention this has worked for months? I did NOTHING to it, yet it’s irrevocably broken, apparently. I have much, much more important things that I should be doing, not fixing code that shouldn’t be broken.

How do I fix this? Thanks for your time…

Subject: Looks familar

I saw a customer report a similar issue at the LS level. So it could be something at the LSXBE area.

You would get a blank title or empty object if you called currentDatabase() a second time.

So try changing:

ns.Getdatabase(ns.currentDatabase.server, “\EE\EECatsLog.nsf”).title

to:

ns.Getdatabase(db.server, “\EE\EECatsLog.nsf”).title

If that doesn’t resolve it, then assign that to a variable before calling title().

If that works there is an SPR I wrote (no access to it at this time though).

Subject: Read it again. saw your close update.

If that is the case then it is a new issue.

Subject: I’ve seen cases where it APPEARED to be bypassing the error handler…

LotusScript error trapping is very, very reliable. There is no way an “object variable not set” error would not be trapped if in fact error trapping is in effect on the code line. It doesn’t matter what method or property of the object it’s trying to call.

What probably occurred is that the error handler trapped the error, but the code in the error handler caused another error. By default, error trapping is disabled while handling an error (because otherwise an error occurring in the error handler would cause an infinite loop, which is worse than the default cryptic error). You can re-enable the error trapping in the error handler with another On Error statement, but it’s better to just be pro-active in your error trapping code, using a test if obj Is Nothing before attempting to use any object.

Subject: Thanks Andre! I’ll check that out…