views:

322

answers:

1

I'm trying to open names.nsf in code. The piece of code has been working for a while but suddenly, I'm getting null. Any idea why? I don't seem to be getting any errors and I don't know how to work out what's wrong.

I can open the database from the Notes client on the same machine.

UPDATE

Here's the code. The fields are initialised in the constructor. The null reference occurs on the .IsOpen() message.

public class DominoPersonSearcher
{
    private string _serverName;
    private string _databaseFileName;
    private string _password;
    private Domino.NotesDatabase OpenDatabase(out Domino.NotesSession notesSession)
    {
        notesSession = new Domino.NotesSessionClass();
        notesSession.Initialize(this._password);

        Domino.NotesDatabase notesDatabase;
        notesDatabase = notesSession.GetDatabase(this._serverName, this._databaseFileName, false);

        if (!(notesDatabase.IsOpen))
        {
            notesDatabase.Open();
        }
        return notesDatabase;
    }

This code is C# and runs on a web server; it's not inside a db - it's running outside of Notes, just calling into it. I've used this exact mechanism many times. It uses a .NET wrapper around the Lotus Domino Objects COM C:\notes\domobj.tlb called Interop.Domino.dll. Domino is installed on a different server.

+5  A: 

Returning null from getdatabase means you could not access the database. If you're running this as a java agent then it will run under your privileges. A server can be configured to restrict who can access databases via agents on a server.

Try opening another database on the server that you have the same level of access to or a database you have manager access to. Doing this, checks to see if you can open databases via agents on the server. If you can't open this database either, then it sounds like a permission problem with the server. It's not the database itself, because you can access it via the Notes client.

One way around it, is that you can can also tell the agent to run under the server's ID. This usually gets around access issues. The agent's security options is the last tab, on the "agent properties" dialog box. Note that this option can also be controlled via server settings, and you'll get an error message if you're not allowed to do this either. Let me know how you go..

giulio
It's not an agent: I'm using the domino COM object. I'm using the same ID that I've logged in with - I only supply the password and it uses the last logged on user. The thing is, it was working - I haven't changed any of my code. Well, not this bit anyway. Is it only security that causes it to return null?
ssg31415926
I need to know now how you are structuring your code. Where is this code running from ? I'm assuming it's still being called from within a notes database, like a form or a view then ? It should be possible to trouble shoot. And yes, it sounds like a permissions problem with the server so far. I still recommend that you run the same code on another db to see if you get the same problem. Just substitute the filename ("names.nsf") for another db file on the same server. The names.nsf typically only has reader access for users because it's the backbone for user management on a Domino server.
giulio
I've looked at the code. it looks fine. So, have you tried opening another database on the same server with the same code ? I go into "debug mode" now, by putting print statements to check the values of my parameters I am passing to ensure that they're correct. I haven't done much with COM, but it shouldn't be case sensitive filenames.
giulio
Thank you. I took your approach in mind and started to check everything. I even went into Notes.ini and it didn't look right so I compared it to a known-working machine and there were bits missing. Everything seems to be okay now that I've sorted notes.ini out. I haven't found the culprit yet but the hunt has begun!
ssg31415926
Good to hear. Just so I understand, you're running the code in a .Net application that uses the Domino "COM" that is also installed on a PC ?
giulio
Yes, that's right. The Lotus Domino Objects COM library is installed as part of the Notes client: . .NET builds a wrapper around the COM library, called Interop.Domino.dll, which translates the COM calls into .NET and marshals data to and fro. The .Net app has to be installed on a machine with the Notes client.
ssg31415926