Domino Code Fragment

Code Name*
Simple Test for Reading from an ODBC Data Source Using LotusScript
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.141.152.173
Description*
The following test script will evaluate whether you can read from an ODBC source using
LotusScript
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
The script, when executed from a button, will display a messagebox containing data found in
the first column of each column in the data source. If the operation is not completed
successfully, it is likely that the data source is not configured properly.

Important: Complete each of the four steps below before running the script.

1. Create a new agent and add the following UseLSX command to the Options event:

UseLSX "*LSXODBC"

2. Add the following script to the Initialize event of the agent. NOTE: Do not add the
'Sub' and 'End Sub' lines.

Sub Initialize
Dim con As New ODBCConnection
Dim qry As New ODBCQuery
Dim res As New ODBCResultSet


If Con.ConnectTo("Addresses")Then
Set Qry.Connection = Con
Qry.SQL = "select * from ADDRESS"
Set Res.Query = Qry
Res.Execute
Call Res.FirstRow
Messagebox ("The value found in the first column of the first row of the
table is " & Res.GetValue(1))
Res.Close(DB_Close)
con.DisConnect
Else
Messagebox ("Could not connect to data source")
End If
End Sub


3. Replace the "Addresses" data source with the name of any data source registered in your
ODBC control panel.

4. Replace the "ADDRESS" table name with a valid table name contained in the specified data
source.


Supporting Information:
In order to access external databases through ODBC using LotusScript, you must include the
following statement in the (Options) event of the (Global) object.


UseLSX "*LSXODBC"


The following is an excerpt from the Notes R4 on-line help.

Accessing external databases through ODBC using LotusScript

The ODBCConnection, ODBCQuery, and ODBCResultSet classes provide properties and
methods for accessing external databases through the ODBC (Open Database Connectivity)
standard.


You must put the following statement in the (Options) event of the (Global) object to access
the OBDC classes:

UseLSX "*LSXODBC"

You can handle ODBC errors with On Error the same as for Notes methods. In addition, the
ODBC methods return a Boolean status code to indicate success or failure, unless there

is another return, and provide methods GetError, GetErrorMessage, and GetExtendedErrorMessage
to access the last error that occurred.

Include the file LSXODBC.LSS to use the ODBC error names and other constants.