Failed to access local database through local session. ERROR:Database has not been opened yet

On notes side, I created a local nsf called localNSF.nsf. Then I wrote code try to access this nsf. I do not have Domino started, and nsf is only in the …/Lotus/Notes/data folder. The code are as follow:

[code]-------------------------------------------------------

lotus.notes.NotesThread.sinitThread();

lotus.domino.Session localSession = null;

try {// ------------- try to get a local session

        localSession = NotesFactory.createSession();

    } catch (NotesException e) {

        e.printStackTrace();

    }

if(localSession == null){

        System.out.println("failed to get local session.");

    }else{

        System.out.println("got local session.");

    }

//----------- register the id file

    String idfile = "D:\\Program Files\\Lotus\\Notes\\data\\user.id";

    Registration r;

    try {

        r = localSession.createRegistration();

        r.switchToID(idfile, password);

    } catch (NotesException e1) {

        // TODO Auto-generated catch block

        e1.printStackTrace();

    }

//------------- try to get database

    lotus.domino.Database db = null;

    try {

        db = localSession.getDatabase("","localNSF");

    } catch (NotesException e) {

        e.printStackTrace();

    }

    

    if(db == null){

        System.out.println("failed to get local db.");

    }else{

        System.out.println("got local db.");

    }

    

    try {

        System.out.println("db title = " + db.getLastModified());

    } catch (NotesException e) {

        e.printStackTrace();

    }



    lotus.notes.NotesThread.stermThread();

[/code]-------------------------------------------------

before execute the code above, I include the location of notes.jar, ncso.jar and nlsxbe.dll in the PATH.

then when executing the code, I could getSession() ‘successfully’, I mean the ‘localSession’ is not null; then I could get database, it mean ‘db’ is not null; but when doing ‘db.getLastModified()’ call, I caught the following error:

[error] -----------------------------------------------

NotesException: Database localNSF.nsf has not been opened yet

at lotus.domino.local.NotesBase.PropGetDate(Native Method)

at lotus.domino.local.Database.getLastModified(Unknown Source)

at LocalSessionTry.main(LocalSessionTry.java:62)

[/error] -----------------------------------------------

Could anybody shed light on this? Is the session created successfully though it is not null? And why I could get a not-null db, but I could not get any content in it?

Subject: the error “database has not been opened yet”…

… when you have specified the server and filepath, means that the database could not be opened. The problem really occurred at an earlier point, before the line that throws the error. On this line, in fact:

db = localSession.getDatabase(“”,“localNSF”);

This probably is because the file does not exist at that path. There might be other reasons. What happens when you try to open the database from the Notes client using that same ID?

Subject: default nsf path is not …/Notes/data

yes, it seems to be the location of the database.

I thought if I create a local session, it is a session to a particular notes client(not domino), so if I call getDatabase() of the session, it see …/Notes/data as the default folder to get database.

But after some test, I found it sees …/Domino/data as the default folder. So when executing my previous code, there is no database ‘localNSF’ there under …/Domino/data, and the database was not gained indeed.

For now, to access a database locates at some places other then the default one, I should give the full path of the database.

Subject: Example

Directly from notes help (isOpen)

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void isitopen(Database db) throws NotesException {

if (db.isOpen())

  System.out.println("\"" + db.getTitle() + 

       "\" is open");

else

  System.out.println("\"" + db.getTitle() + 

       "\" is not open"); }

public void NotesMain() {

try {

  Session session = getSession();

  AgentContext agentContext = session.getAgentContext();

  // (Your code goes here)

  DbDirectory Dir = session.getDbDirectory(null);

  Database db = 

     Dir.getFirstDatabase(DbDirectory.DATABASE);

  isitopen(db);

  db.open();

  isitopen(db);

} catch(Exception e) {

  e.printStackTrace();

}

}

}

Subject: this is not a solution that we expected

Thanks for your reply, but we noticed that, the class you copied here is extended from AgentBase.

For us, we want this class run as an application but not an agent. So the code here won’t work for us.

There are two ways to create a session, one is the one you mentioned in your response, and the other one is call NotesFactory.createSession() just as we did in our sample code.

Subject: doesn’t matter

The agentbase doesnt matter, it’s the method IsOpen that you need.

Subject: called db.open method, but still error

Thanks for your reminding! I modified my code to explicitly call Database.open() method, but got the following error:NotesException: File does not exist

at lotus.domino.local.Database.Nopen(Native Method)

at lotus.domino.local.Database.open(Unknown Source)

at LocalSessionTry.main(LocalSessionTry.java:67)

The database that I created is a local one, which locates under the …/notes/data folder. And I check the location, the nsf is there.

There are different Notes client installed on my machine. I am not sure if this could be the cause of the issue, but I started only one version and called Session.getNotesVersion() method in code to verify the version I try to access is the one I started.

Subject: it picks the lotus/Domino/data as the default folder!

I changed to access a nsf which locates at the lotus/Domino/data, and it works.

To access a nsf locates some where else, I need to give the full path of that nsf file.