在 C# 中通过副本 ID 打开 Lotus Notes 数据库

发布于 2024-08-04 02:19:24 字数 1284 浏览 5 评论 0原文

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

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 更改,则任何操作都将不再有效。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

香草可樂 2024-08-11 02:19:24

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

Set notesDbDirectory = notesSession.GetDbDirectory( serverName$ )

因此您可以使用下面的代码通过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 的数据库,就像单击 DBLink 或书签时 Notes 客户端所做的那样。然而,没有(或似乎)没有办法使用 Notes API 来做到这一点。

我的建议是按名称循环遍历潜在服务器的硬编码列表,并检查是否找到数据库(如果未找到数据库,OpenDatabaseByReplicaID 方法将返回 ERR_SYS_FILE_NOT_FOUND(错误 0FA3))。如果这不是一个好的选择,也许您可​​以轻松地在应用程序的管理菜单中公开服务器名称,以便在服务器名称在某个时刻发生更改时可以轻松更改它。

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.

殤城〤 2024-08-11 02:19:24

设置数据库 = 新 NotesDatabase("")
调用database.OpenByReplicaID("repid")

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文