views:

1066

answers:

3

I created a program a while ago using C# that does some automation for a completely different program, but found that I need to access data from a Lotus Notes database. The only problem is, I can only seem to figure out how to open the database by the server's name (using session.GetDatabase())... I can't figure out how to open it by Replica ID. Does anyone know how I would go about that? (I don't want my program going down every time the server changes.)

public static string[] GetLotusNotesHelpTickets()
{
    NotesSession session = new NotesSession();
    session.Initialize(Password);
    // 85256B45:000EE057 = NTNOTES1A Server Replica ID
    NotesDatabase database = session.GetDatabase("NTNOTES1A", "is/gs/gshd.nsf", false);
    string SearchFormula = string.Concat("Form = \"Call Ticket\""
                                    , " & GroupAssignedTo = \"Business Systems\""
                                    , " & CallStatus = \"Open\"");
    NotesDocumentCollection collection = database.Search(SearchFormula, null, 0);
    NotesDocument document = collection.GetFirstDocument();
    string[] ticketList = new string[collection.Count];

    for (int i = 0; i < collection.Count; ++i)
    {
        ticketList[i] = ((object[])(document.GetItemValue("TicketNumber")))[0].ToString();
        document = collection.GetNextDocument(document);
    }

    document = null;
    collection = null;
    database = null;
    session = null;

    return ticketList;
}

This code is working fine, but if the server changed from NTNOTES1A, then nothing is going to work anymore.

+2  A: 

Hi, you'll need to use the notesDbDirectory.OpenDatabaseByReplicaID(rid$) method. To get the NotesDbDirectory, you can use the getDbDirectory method of the session

Set notesDbDirectory = notesSession.GetDbDirectory( serverName$ )

So you can use the code below to get a database by replicaID.

public static string[] GetLotusNotesHelpTickets()
{
    NotesSession session = new NotesSession();
    session.Initialize(Password);

    Set notesDBDirectory = session.GetDbDirectory("NTNOTES1A")
    // 85256B45:000EE057 = NTNOTES1A Server Replica ID
    NotesDatabase database = notesDBDirectory.OpenDatabaseByReplicaID("85256B45:000EE057")
    string SearchFormula = string.Concat("Form = \"Call Ticket\""
                                    , " & GroupAssignedTo = \"Business Systems\""
                                    , " & CallStatus = \"Open\"");
    NotesDocumentCollection collection = database.Search(SearchFormula, null, 0);
    NotesDocument document = collection.GetFirstDocument();
    string[] ticketList = new string[collection.Count];

    for (int i = 0; i < collection.Count; ++i)
    {
        ticketList[i] = ((object[])(document.GetItemValue("TicketNumber")))[0].ToString();
        document = collection.GetNextDocument(document);
    }

    document = null;
    collection = null;
    database = null;
    session = null;

    return ticketList;
}

Unfortunately, this only solves half of your problem. I know you'd rather just tell Notes to fetch the database with a particular replicaID from the server closest to the client, just like the Notes Client does when you click on a DBLink or Bookmark. However, there is (or appears to be) no way to do that using the Notes APIs.

My suggestion is to either loop through a hard-coded list of potential servers by name, and check to see if the database is found (the OpenDatabaseByReplicaID method returns ERR_SYS_FILE_NOT_FOUND (error 0FA3) if the database is not found). If that's not a good option, perhaps you can easily expose the servername in an admin menu of your app so it can be changed easily if the server name changes at some point.

Ken Pespisa
So sad... I can't believe that they wouldn't have added in that little feature. I guess if I was going to loop through server names, the Replica ID will probably be unnecessary. Thanks for the answer... Looks like I'll have to do the list of Server names anyway. Sigh - Why can't notes API's ever be easy?
Sivvy
+1  A: 

set database = new NotesDatabase("") call database.OpenByReplicaID("repid")

Andrew Brew
I'm assuming that's LotusScript. I'm writing this in C#, and the "database.OpenByReplicaID("repid")" won't work, because it isn't an overloaded function, and requires 2 parameters... One being the server.
Sivvy
The servername is required in C#?? That kind of defeats the purpose of using the replica id at all. Ah well. In that case, it looks like you are back to using a config doc (or equivalent) to specify the preferred server. Perhaps you might attempt a connection to the preferred server, and as a backup if that doesn't work, get a list of all servers in the domain from names.nsf (or from the same config document) and loop through them.
Andrew Brew
Yea... Kind of stupid that they'd even have the option to open by replicaID, but no reason to use it... Yet another reason for Notes to annoy me.
Sivvy
A: 

can anybody tel me how to update values... this works great btw...

ram