API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Get Database Function
It's pretty easy to get a database in LotusScript - NotesSession.GetDatabase(server$, path$[, createOnFail]). But what if you don't want to "create on fail"? The method will trigger an error if the database doesn't exist. In a lot of my applications, I want to gracefully handle errors. Maybe the user typed in the wrong database path - I want to give that error. Or maybe it's something that is purposely checking for missing databases - I don't want to error when it doesn't exist. So I wrote a function to get a database. If the database doesn't exist, the function returns the LotusScript constant Nothing instead of triggering an error.

Function GetDatabase(session As NotesSession, server As String, fileName As String) As NotesDatabase
   On Error GoTo BubbleError
   ' Open the database. If it can't be found or can't be opened, return NOTHING
   Dim retDb As NotesDatabase

   On Error Resume Next
   Set retDb = session.Getdatabase(server, fileName, False)
   If not retDb.Isopen Then Call retDb.Open("", "")
   If not retDb.Isopen Then Set retDb = Nothing
   On Error Goto BubbleError
   If Err <> 0 Then
      Err = 0
      Set retDb = Nothing
   End If

   Set GetDatabase = retDb

   Exit Function
BubbleError:
   Error Err, Error$ & Chr$(10) & "in function " & Getthreadinfo(1) & ", line " & Cstr(Erl)
End Function