Hi ,
I have the following code in VB6 which "dismantles a text file and writes it into a SQL database table.It worked fine for 2 months and suddenly stopped.Here's the code(part of it)
Private Sub Collect()
Dim f As Integer
Dim strSourceFile As String
Dim iFirstColon As Integer
Dim strTextLine As String
Dim strFieldName As String
Dim strValue As String
Dim pcs As Integer
Dim cn
Dim RS
Dim ipcs
Dim Throughput
Set cn = CreateObject("ADODB.Connec
tion")
Set RS = New ADODB.Recordset
cn.Open "driver=SQL Server;server=(local);uid=
;pwd=;data
base=Check
Weighers;"
RS.Open "statex1", cn, adOpenDynamic, adCmdTable, adLockPessimistic
strSourceFile = "C:/statex.txt"
f = FreeFile
Open strSourceFile For Input As #f
Do Until EOF(f)
Line Input #f, strTextLine
Select Case Trim$(strTextLine)
Case "BLOCKBEGIN"
RS.AddNew
Case "BLOCKEND"
'On Error Resume Next 'This line is to Avoid duplicates as I set Primary Key the Duration
RS.Update
Case Else
iFirstColon = InStr(strTextLine, ":")
strFieldName = Left$(strTextLine, iFirstColon - 1)
strValue = Mid$(strTextLine, iFirstColon + 1)
RS.Fields(strFieldName).Va
lue = strValue
End Select
Loop
Close #f
RS.Close
cn.Close
loadflexgrid
End Sub
so the SQL TABLE has a primary key on the Duration column.For my understanding if the recorset encounters a value for the duration the same as an existing one in SQL then it should skip the that entry and continue inserting the next entries.Unfortunately this is not happening.I am just wondering why??
What actuallythe story is that the text file is being updated every 2 minutes with new rows (might be 1 row or 100 rows) but the rest of the rows is still on the text file.What I would luike to achieve is to insert in SQL only the new rows in the text file.I am doing something wrong somewhere however I cannot explain why it worked up untill now.Maybe because I exhausted all the possible distinct values for the duration coulmn?An whatever Is coming in th etext file has got in the duration a value which is already present in the database.If I remove the primary key constraint from the table then the code will insert all the entries from the text file which will create plenty of duplicates.
What is wronmg??