Search code examples
javascriptxpages

session.getDatabase returns null


I'm trying to open my own database via Xpage using JS on beforePageLoad event.

I have this code:

var db:NotesDatabase = session.getDatabase("x", "y",false);
var dbCount = db.getAllDocuments().getCount();

X contains the server name and y the database name. I've tried this with other databases and still got null all the time, I've tried different ways to access the database and still no results. Any suggestions where I might look for the reason why is this happening?


Solution

  • Very common mistake with hard coded path is missing escape character for backslash, used in file path.

    Chceck you path and replace single backslashes \ with double backslashes \\. Another option is to use single slah / - it is valid directory/folder separator on both platforms (Windows and Linux).

    I strongly recommend NOT to use hard coded paths in sources. Some form of configuration will solve your problem (properties file, profile document, configuration document, ...) - stored value need not to be escaped.