I have some code that
- Looks at the max ID in Table A
- Fetches the records from Table B with ID > Max ID from the Table A
- Loops through each record that it needs to add (are these the records from Table A????)
- Finds all records in Table C that is related to the ID from Table B and inserts those records into Table D.
For some reason the loop stops unexpectedly after fetching and inserting some records with no error. It stops at random stages. Sometimes it adds 20 records sometimes 100 and sometimes 1000+. Is it to do with my logic or is it a server setting maybe? The web application .Net Framework 4.5 and is hosted on a Windows 2019 Server.
Here is the logic I follow. I specifically don't add the code as it is quite elaborate and I thought I'd share the logic I follow rather to get some suggestions on why this might be happening.
GetNewRecords()
MaxIdA = Select max id in Table A
Select all records in Table B with id > MaxIdA
if reader has rows
While reader.Read
NextID = reader[0]
AddNewRecordToTableB()
Select all records in Table C where IdLink = NextID
if reader2 has rows
While reader2.Read
NewDetail = reader2[..]
AddNewRecordToTableD()
Connection2 Dispose
AddNewRecordToTableB()
Insert into TableB ….
AddNewRecordToTableD()
Insert into Tabled ….
throw ex;)