2009-09-11 101 views
0

我前段时间使用C#创建了一个程序,该程序为完全不同的程序执行了一些自动化操作,但发现需要从Lotus Notes数据库访问数据。唯一的问题是,我似乎只能弄清楚如何通过服务器的名称(使用session.GetDatabase())打开数据库...我无法弄清楚如何通过副本ID打开它。有谁知道我会怎么做? (我不希望我的程序每次服务器更改下去。)通过C#中的副本ID打开Lotus Notes数据库

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; 
} 

此代码工作正常,但如果从NTNOTES1A改变了服务器,那么没有什么会再工作。

回答

2

您需要使用notesDbDirectory.OpenDatabaseByReplicaID(rid $)方法。要获得NotesDbDirectory,您可以使用会话

Set notesDbDirectory = notesSession.GetDbDirectory(serverName$) 

的getDbDirectory方法所以,你可以使用下面的代码通过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; 
} 

不幸的是,这只能解决您的一半问题。我知道你更愿意告诉Notes使用离客户端最近的服务器上的特定副本ID来获取数据库,就像Notes客户端在单击DBLink或书签时所做的一样。但是,使用Notes APIs存在(或似乎是)无法做到这一点。

我的建议是按名称循环访问潜在服务器的硬编码列表,并检查是否找到数据库(如果未找到数据库,OpenDatabaseByReplicaID方法返回ERR_SYS_FILE_NOT_FOUND(错误0FA3))。如果这不是一个好的选择,也许你可以很容易地在应用程序的管理菜单中公开服务器名称,所以如果服务器名称在某些时候改变,它可以很容易地更改。

+0

如此悲伤......我不能相信他们不会在小功能添加。我猜如果我要循环访问服务器名称,副本ID可能是不必要的。感谢您的答案...看起来我必须做任何服务器名称列表。叹气 - 为什么不能记录API的容易? – Sivvy 2009-09-11 18:02:17

1

组数据库=新NotesDatabase的(“”) 调用database.OpenByReplicaID(“REPID”)

+0

我假设是LotusScript。我正在用C#写这个,而“database.OpenByReplicaID(”repid“)”将不起作用,因为它不是一个重载函数,需要2个参数......一个是服务器。 – Sivvy 2009-11-13 16:29:07

+0

C#中需要servername吗?这种做法完全违背了使用副本ID的目的。呃,好吧。在这种情况下,它看起来像你回到使用配置文档(或等效)来指定首选服务器。也许你可能试图连接到首选的服务器,并且如果不起作用则作为备份,从names.nsf(或来自同一个配置文档)获取域中所有服务器的列表并循环遍历它们。 – 2009-11-16 22:04:50

+0

是啊...有点愚蠢的是,他们甚至可以选择通过replicaID打开,但没有理由使用它...另一个原因使Notes烦我。 – Sivvy 2009-11-17 19:08:48