2009-09-11 95 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