1
votes

I'm trying to open a view from a Lotus Notes database using the NotesSQL ODBC driver and the COM API. When I use Access to 'link to external data', using notesSQL over 380 'tables' are listed.

The following C# code was written with the COM API to list out the views: only 230 objects are returned. It appears that actual tables that contain the data are excluded from the Views list.

var _someDatabase = _lotesNotesSession.GetDatabase("MainServer/Server/Company/US", @"Groups\Location\someNotesDatabase", false);

        var _views = _someDatabase.Views;
        foreach (var view in _views)
            Console.WriteLine(view.Name);

What is the proper way to connect to the tables that actually contain the data?

1

1 Answers

3
votes

Revised based on your comments.

Okay... So you are not using NotesSQL. You are using the Notes COM API. If you want to get a list of all the Views in a Notes Database, you use the _someDatabase.Views property, as you have done. But to read data out of a Notes database, you need to read NotesDocument objects, which contain NotesItem objects.

There are a number of ways to read NotesDocument objects. E.g.,

  • Using the NotesDatabase.AllDocuments property which gives you a NotesDocumentCollection object containing all the NotesDocuments
  • Using the NotesDatabase.Search method, which gives you a NotesDocumentCollection object containing only the NotesDocument objects that meet a search criterion.
  • Looping through the collection of NotesDocuments associated with a particular view.

I'll briefly cover the last option, because it will underscore a point that I want to make.

Views contain NotesDocument objects in what we call their collection. The same is true of Folders. You've got the views (as an array of NotesView objects) from your call to _someDatabase.Views, so for any of those views, you can do something like this:

thisDoc = view.GetFirstDocument
while (thisDoc != null)
{
    processNotesDocument(thisDoc)
    thisDoc = view.GetNextDocument
} 

And then you could write a processNotesDocument function that uses Notes COM API calls to read the data (i.e. the NotesItem objects) from the NotesDocument. You can look at the documentation for the NotesDocument class to figure out how to do that.

The thing is, before you can go and do that, you'd have to answer the question: which view (or views) do I want to do this in? Or you'd have to choose one of the other methods that I listed above for accessing the NotesDocument objects.

I don't mean to be disrespectful, but I think you're going to need to know a bit more about the data that you are dealing with, and about Lotus Notes database design, before you can address that. I'm infering that from the fact that your question doesn't show that you even know that the basic unit of information in Lotus Notes is called a "document", and Notes programming has a big API and it's just not something that one can usually navigate through without some idea of where you're going in the first place.

Here's a link that will take you to the reference info for the NotesDocument class. It should also bring up navigation for the documenation for all the other classes in the API. But what I think you really need is a tutorial on the basic concepts of Lotus Notes programming, and unfortunately all the good stuff is old and not oriented toward C#. The good news is that the classes and the concepts are all pretty much the same for the API in C# as they are in the LotusScript language that is native to Notes, and not too different from the classes and concepts in in the API for Java -- and even the fairly old stuff is still going to be good on the basics that you need. Here's a link to another StackOverflow question that can help point you in the direction of some material that can help you.

=================================================================================

Original answer from this point on...

First: Is the C# code running under the same Notes ID that Access is? If not, then security restrictions within the Notes database design might be responsible for the different results. Or at least partially responsible. Second: I think you know this (because you used quotes around 'tables'), but there are no tables. The NotesSQL driver only makes it look like there are tables, and it uses both Views and Forms for that. A Notes database with 160 Forms would be a bit unusual, but not entirely unheard of. That might be what you are seeing. Bear in mind, though, that NotesSQL queries against Views will be more efficient than queries against Forms, becuase the former go against the indexes that are pre-built on the server, whereas the latter have to do a search through the entire database. If you need to query for fields that are not included in any existing View, then you can certainly use a query against a Form. You can get the list of Forms via _localDatabase.Forms. But the better way would be to use Domino Designer to add the Views that you need, and then do your NotesSQL query against the Views. Third: But I'm a little confused by why you wrote the above code, because it's not using NotesSQL. It's using the Notes COM API (presumably through the interop DLL) since this is C#. But since you're doing that, then why bother with NotesSQL? You're already using an API that is much better suited for doing operations on Notes/Domino data, and might very well give you a way to get your data more efficiently than NotesSQL can -- without having to add any new Views to the database, though that could depend on your understanding of the existing Views, data relationships, etc. Finally: Unrelated to your actual question, but just some friendly advice: you should really change the name of your variable _localDatabase. Anyone with Notes/Domino experience would likely interpret "local" to refer to a database that is being accessed without going through a Domino server -- which is what I thought at first. But with a closer look at your code, I see that you are actually opening a database on a server named MainServer/Server/Company/US.