LCConnection in agent

Hello everyone

I have an agent which sends documents with attachments. It takes data from Oracle database and then preparing and sending e-mails. The problem is that it should send all e-mails which are in oracle at one time but it sends only one. on the next ru not sends another one and so on. Agent runs every 15 minutes

When i run it in debug mode it’s all OK.

What i made wrong with that?

Here is the code with changed e-mails:

Option Public
Option Declare
UseLSX “*LSXLC”

Sub Initialize()
'Dim ws As New NotesUIWorkspace
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entrycol As NotesViewEntryCollection
Dim doccol As NotesDocumentCollection
Dim entry As NotesViewEntry
Dim doc As notesdocument
Dim newdoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim ndrtitem As NotesRichTextItem
Dim path As String
Dim notes As String
Dim www As String
Dim link As String
Dim sql As String
Dim sql_cd As String
Dim src_connect As New LCConnection (“ORACLE”)
Dim src_update As New LCConnection (“ORACLE”)
Dim src_pliki As New LCConnection (“ORACLE”)
Dim data As String
Dim adres As String
Dim nadawca As NotesName
Dim wynik As Double
Dim count As Double
Dim count_pliki As Double
Dim count_upd As Double
Dim fieldlist As lcfieldlist
Dim pliki As lcfieldlist
Dim UpdateFL As lcfieldlist
Dim i As Integer
Dim nazwapliku As String
Dim fakt,email,stalo,file,extp,comp,korg,plik_nazwa,plik_sciezka,plik_folder As LCField
Dim folder As String
Dim plik As string
Dim object As NotesEmbeddedObject

On Error Resume Next

'On Error GoTo petla

path=“E:\Send\Att”
Set db=session.Currentdatabase
Set fieldlist = New LCFieldlist
Set pliki=New LCFieldlist
Set UpdateFL=New LCFieldlist

src_connect.UserID = “c”
src_connect.Password=“c123”
src_connect.server= “LN”
src_connect.metadata = “table1”
src_connect.Connect
src_pliki.UserID = “c”
src_pliki.Password=“c123”
src_pliki.server= “LN”
src_pliki.metadata = “table2”
src_pliki.Connect
src_update.UserID = “c”
src_update.Password=“c123”
src_update.server= “LN”
src_update.metadata = “table1”
src_update.Connect

sql="select f1,f2,f3,f4,f5,f6,f7 from table1 where status=2

wynik=src_connect.Execute(sql,fieldlist)

count = src_connect.Fetch (fieldlist, 1, 1)
While (count > 0)
If count>0 then
Set fakt=fieldlist.GetField(1)
Set email=fieldlist.GetField(2)
Set stalo=fieldlist.GetField(3)
Set file=fieldlist.GetField(4)
Set extp=fieldlist.GetField(5)
Set comp=fieldlist.GetField(6)
Set korg=fieldlist.Getfield(7)

Set doc=db.Createdocument()
doc.Form=“Memo”
doc.Subject=fakt.value
doc.sendTo=email.value
doc.Principal=“f@a.a”
doc.InetFrom=“f@a.a”
doc.From=“f@a.a”
Set rtitem= New NotesRichTextItem(doc,“Body”)
If korg.Value(0)=1 Then
doc.ReplyTo=“resp@a.a”
End If

If file.text(0)<>“” Then
folder=Replace(extp.Text(0),“/”,“")
plik=path+folder+”"+file.text(0)
Set object= rtitem.Embedobject(EMBED_ATTACHMENT, “”, plik)
If object.name=“” Then
GoTo petla
End If
If doc.Sendto(0)=“” Then
GoTo petla
End If
Else
sql=|select p1,p2,p3 from table2 where fakt=‘|+fakt.value(0)+|’ |
wynik=src_pliki.Execute(sql, pliki)
count_pliki=src_pliki.Fetch(pliki, 1, 1)
If count_pliki<1 Then
GoTo petla
End If

While count_pliki>0
If count_pliki>0 Then
Set plik_nazwa=pliki.GetField(1)
Set plik_sciezka=pliki.GetField(2)
Set plik_folder=pliki.GetField(3)
folder=Replace(plik_folder.Text(0),“/”,“")
plik=path+folder+”"+plik_nazwa.text(0)
Set object= rtitem.Embedobject(EMBED_ATTACHMENT, “”, plik)
If object.name=“” Then
GoTo petla
End If
If doc.Sendto(0)=“” Then
GoTo petla
End If
End If

count_pliki=src_pliki.Fetch(pliki, 1, 1)
Wend

End If

If doc.Sendto(0)=“” Then
GoTo petla
End If
Call doc.Save(true,false)

Call doc.Send(False)
sql=“update table1 set status=3 where f1='”+CStr(fakt.value(0))+"’ "

count_upd=src_update.Execute(sql,UpdateFL)
End if

petla:
count = src_connect.Fetch (fieldlist, 1, 1)
Wend
Call src_update.Disconnect()
Call src_connect.Disconnect()

End Sub

Subject: Thank you for sugestions

Agent sends the message so it has all permissions. The problem is that it exits the loop after first record from oracle.

I’ll try to catch errors in log maybe it helps me in some way

Subject: some suggestions

Somethings to look for and do

By you running the agent it takes on you rights and not what signed the agent.

Put an on error trap . Chances are the agent does not have the correct permissions

Put some print statements in the code and see if that appears in the log.nsf

I noticed the agent is accessing plik=path+folder+""+plik_nazwa.text(0) Does it have rights to this directory?

Subject: Problem solved

Hello

I’ve moved this constructor Set pliki=New LCFieldlist into the loop and it works good now.

Thanks again for your suggestions

Subject: Let us know what it was

When I say permission I also refer to windows as well perhaps it cant overlay an existing file? Either way let us know what you find