Using lsxlc instead of lsxodbc

I am trying to develop a agent that connects to a db2 database with lsxlc. I used a odbc in the past with lsxodbc but i want to use lsxlc.

The code with ODBC looks like this:

Dim con As New ODBCConnection

Dim query As New ODBCQuery

Dim res As New ODBCResultSet

Dim nsesCurrent As New NotesSession

Dim t_Userid As String

Dim t_password As String

Dim t_lib As String

Dim t_file As String

Dim cdoc As NotesDocument

Dim cview As NotesView

Dim dblCounter As Double

Set cview = ndbCurrent.getview("CONIMPORT")

Set cdoc = cview.getfirstdocument





t_Userid = cdoc.conIMPORTUserid(0)

t_password = cdoc.conIMPORTPassword(0)

t_lib = cdoc.conPFSBLib(0)

t_file = cdoc.conPFSBFile(0)



retCode = con.ConnectTo( t_lib , t_Userid , t_Password )

query.sql = "Select * from " + t_file  

Set query.connection =  con

Set  res.query = query



res.CacheLimit = 100

res. FetchBatchSize = 50

Call res.execute







If res.numrows <> 0 Then

	Print "Succesvolle connectie overhalen gegevens"

	

	Do 

		res.nextrow

		If (res.geterror = DBstsSUCCESS) Then

			

			'Variabelen worden gevuld

			'De namen van de variabelen zijn het zelfde als de veldnamen op AS/400

			

			

			varSBFIL   = res.getvalue("SBFIL#") 'filiaalnummer	

			varSBDAG  = res.getvalue("SBDAG#") 'Dag nummer

			varSBALTF   = res.getvalue("SBALTF") 'Tijd

			varSBBED   = res.getvalue("SBBED#") 'Dag nummer

			varSBBETD   = res.getvalue("SBBETD") 'Tijd

			varSBESD   = res.getvalue("SBESD#") 'Dag nummer

			varSBESTD  = res.getvalue("SBESTD") 'Tijd

			

			Set ndocTemp = ndbSpoorboekje.CreateDocument

			With ndocTemp

				Call .replaceItemValue("Form","nfrmPFSB")

				Call .replaceItemValue("SBFIL", varSBFIL)

				Call .replaceItemValue("SBDAG", varSBDAG)

				Call .replaceItemValue("SBALTF",varSBALTF)

				Call .replaceItemValue("SBBED",varSBBED)

				Call .replaceItemValue("SBBETD" ,varSBBETD)

				Call .replaceItemValue("SBESD", varSBESD)

				Call .replaceItemValue("SBESTD", varSBESTD)

				Call .save(True,False)

			End With

			dblCounter = dblCounter + 1

			

		End If

	Loop Until res.IsEndOfData

End If



Print "Collected for PFSB: " & Cstr(dblCounter) & " documents."



Exit Sub

errorHandler:

If con.GetError <> DBstsSuccess Then 

	con.Disconnect

	Messagebox con.GetErrorMessage,, "Connect"

Elseif query.GetError <> DBstsSuccess Then

	con.Disconnect

	Messagebox qruey.GetErrorMessage,, "Query"

Elseif res.GetError <> DBstsSuccess Then

	errorval% = res.GetError

	Print "Error detail: " & res.GetExtendedErrorMessage(errorval%)	

	Messagebox "Error detail: " & res.GetExtendedErrorMessage(errorval%)	

	con.Disconnect

	Messagebox res.GetErrorMessage,, "Result"

End If

Exit Sub

But how must I change the code for lsxlc? Do i have to install connectors on the domino server an my client or not? The domino server is a iSeries release 5.

I have found some code on the help but I get the error message “Cannot load connector library db2” on my client. It is really gets frustating.

Subject: Using lsxlc instead of lsxodbc

Here is some sample code to help you along:

Dim session As New NotesSession

If session.IsOnServer Then

Set lccon = New LCConnection(“db2”)

lccon.server = “db2_database_name”

Else

Set lccon = New LCConnection(“odbc2”)

lccon.server = “odbc_dsn”

end if

lccon.userid = “iseries_user”

lccon.password = “iseries_pass”

Call lccon.Connect

This just sets up the connection, you have to use a LCFieldList to get results. You may want to check the Enterprise Integration forum for more information.

HTH,

Charles

P.S. DO NOT USE THE “odbc2” CONNECTOR ON YOUR ISERIES!! IT WILL CRASH THE DOMINO SERVER!!

Subject: RE: Using lsxlc instead of lsxodbc

Thanks for your response. I changed the code a bit and changed it into:

Dim statement As String

Dim count As Double

Dim connect As New LCConnection ("db2") 

statement = "Select * from KDCPRDDTA.PFOR"

Dim conFldLst As New LCFieldList 

Dim conFldLstRecord As New LCFieldList 

’ this section assigns the appropriate properties to connect to DB2

connect.Database= "i5" 



connect.Userid = "FARTDOM" 



connect.Password = "fartdom" 



connect.Metadata = "pfor" 

’ connect to DB2

connect.Connect 

’ now perform the catalog action – in this case,

’ for fields in the ‘customer’ table.

If (connect.Catalog (LCOBJECT_FIELD, conFldLst) = 0) Then 

	

	Print "No tables were found (table does not exist)." 

	

Else 

	

' fetch the results 

	

	Dim nameField As LCField, typeField As LCField 

	

	Set nameField = conFldLst.GetField(1) 

	

	

	Print "The list of columns in the '" & _

	connect.Metadata & "' table include:" 

	

	While (connect.Fetch (conFldLst) > 0) 			

		

		Print " nameField:    " & nameField.text(0) 

		

	Wend 

	

	

	count = connect.Execute (statement, conFldLst)

	Print "Found " & Cstr(count)

End If 

When I run the agent on the domino server I get a connetion and also the name of the fields in the print statement. When the codes executes the sql statement I get “Found: -1”. I am sure that the table is not empty.

What is wrong with the code ??