Agent inserting record twice in SQL Server

Hello,

Can any one tell me why following lotus notes agent inserting records twice in SQL Server table?

View is indexed and first column is Categorized and sorted.

Sub Initialize

Dim session As New NotesSession

Dim doc As NotesDocument

Dim Item As NotesItem

Dim currentLog As NotesLog

Dim Poview, view2 As NotesView

Dim Postatus As String

Dim Apps As Variant

Dim AppsDate As Variant

Dim AppBy As String

Dim AppByDate As String

Dim key As String

Dim view As NotesView

Dim con As New ODBCConnection

Dim qry As New ODBCQuery

Dim result As New ODBCResultSet

Dim msg As String

Dim user, as400ID As String

user = session.CommonUserName

Dim userview As NotesView

Dim userdoc As NotesDocument

Set db = session.CurrentDatabase

Set view = db.GetView (“byba” )

Set con = New ODBCConnection

Set qry.Connection = con

Set result.Query = qry

temp = con.ConnectTo(“TEST”, “”,“”)

qry.SQL = “SELECT * FROM POSUM”

result.Execute

rows = result.NumRows

Set view2 = db.getview(“SQLInsert”)

Set doc2=view2.GetFirstDocument

While Not (doc2 Is Nothing)

result.NextRow

result.AddRow

a= doc2.PoByr(0)

b=doc2.PoAst(0)

c=doc2.PoPlan(0)

Call result.SetValue(“VPOBYR”,a)

Call result.SetValue(“VPOAST”,b)

Call result.SetValue(“VPOPLN”,c)

result.UpdateRow

Call doc2.ReplaceItemValue(“sqlrecupdated”, “Yes”)

Call doc2.Save(True,False)

Set doc2=view2.GetNextDocument(doc2)

On Error Resume Next

Wend

result.Close(DB_CLOSE)

con.Disconnect

End Sub

Subject: RE: Agent inserting record twice in SQL Server

Well, did you debug it?

I suspect you’re processing the same document multiple times, owing to your modifying documents without having set the view AutoUpdate property = False. If your modification repositions them in the view, then when you get the next document you may be getting a document you already processed, which you thought you had passed by.

Subject: RE: Agent inserting record twice in SQL Server

Thanks for your reply.

I set view.Autoupdate = FALSE

but still it is inserting records twice in SQL Server

Any idea why?

Thanks

MS

Subject: RE: Agent inserting record twice in SQL Server

I’m sorry, but I’m not going to try to run your code it in my head, when you have a perfectly good debugger there and could debug it for real, and in addition you have your input data and I don’t.

You’re getting duplicate entries because you’re issuing the insert command multiple times. Look at your data. Do you have duplicate data in the Notes database? Step through your code and note down what you’re sending. Reduce your data to just a few records so that you can keep track of what’s already been written.