I am having below code, code is summarized for better understanding, I have try catch
blocks in each delete statements. :-
foreach(var item in listEntry)
{
.. Calculation code
string deletedata = "DELETE FROM [" + schemaName + "].[OT] WHERE CompanyId=" + companyId + " AND EmployeeId = " + StrECode + " AND OTDate = '" + StrInputDate.ToString("yyyy-MM-dd") + "'";
ctx.Database.ExecuteSqlCommand(deletedata);
.. Large Calculation code
string deletedata1 = "DELETE FROM [" + schemaName + "].[ENTRY] WHERE CompanyId=" + companyId + " AND EmployeeId = " + StrECode + " AND EntryDate = '" + StrDate.ToString("yyyy-MM-dd") + "'";
ctx.Database.ExecuteSqlCommand(deletedata1);
}
BulkInsert(parameters);
BulkInsert(parameters);
I am simply deleting the records in a foreach loop then i am performing Bulk Insert. It was all working good but now data volume has increased. the foreach loops for 50,000 times.
Now what is happening is for some unknown reason application is stopping in the middle & it breaks somewhere in the foreach. so the data is getting deleted in large volumes & the Bulk Insert is not performed, so there is huge data loss.
I am not getting any error as so i also have logs, but the application doesn't reach the BulkInsert. And this is happening in some rare cases & not all the time.
What can i do in such a scenario? How to perform Bulk Delete? How to roll back transactions in my case?