Link to home
Start Free TrialLog in
Avatar of Mark Bakelaar
Mark BakelaarFlag for Norway

asked on

Connect to Lotus Notes nsf file using VB.NET

Hi Experts,
I need to connect to a Lotus Notes database. I only need a "select" command to get the data for regular processing. I do not need to update the database. I feel I want to accomplish something very standard by just connecting to the local server, but I keep running into the following problems:
- If I set or not set a password when I run the application I am prompted for a password
- The following error follows from the "Catch" section in the code below

Error: System.Data.Odbc.OdbcException: ERROR [42S02] [Lotus][ODBC Lotus Notes]Base table not found - RepCapUtil

My knowledge of Notes is very limited. I hope someone can provide me with some sample code or a good link,

Regards, Mark
Imports System
Imports System.Data
Imports System.Data.Odbc
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Set up connection string
        Dim connString As String = "Driver=Lotus NotesSQL Driver (*.nsf);" & _
                   "Server=local;" & _
                   "Database=c:\notes\data\KPI\KPITool.nsf;" '& _
        '"UserName=username;" & _
        '"Password=password"
        ' Set up query string
        Dim CmdString As String = "SELECT * FROM RepCapUtil"
        'Declare Connection and DataReader variables
        Dim Conn As OdbcConnection = Nothing
        Dim Reader As OdbcDataReader = Nothing
        Try
            'Open Connection
            Conn = New OdbcConnection(connString)
            Conn.Open()
            'Execute Query
            Dim Cmd As New OdbcCommand(CmdString, Conn)
            Reader = Cmd.ExecuteReader()
            'Display output header
            Console.WriteLine("Querying database {0} with query {1}" & ControlChars.NewLine, Conn.Database, Cmd.CommandText)
            Console.WriteLine("Terminal")
            'Process The Result Set
            While (Reader.Read())
                Console.WriteLine(Reader("CargoType").PadLeft(9) & ControlChars.Tab & Reader(1))
            End While
        Catch ex As Exception
            Console.WriteLine("Error: {0}", ex)
        Finally
            Conn.Close()
        End Try
    End Sub
End Class

Open in new window

SOLUTION
Avatar of Smart_Man
Smart_Man
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
glad it worked for you

:)
It is not working for me. it gives the below error message.

ERROR [IM005] [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_DBC failed.

Any advice will be a great help

Thanks,

Tajudeen