The issue i'm trying to solve is as follows:
I have a process that ingests data from a file and inserts certain things in multiple tables, as it is now it is all done with one transaction, however with very large data sets the rollback or the commit time out and fail, no matter what i set the time out to (at least as far as all my attempts have shown me). So it was decided that I need to rewrite the functionality to "chop" the task up. As it currently stands the pseudo code for the current code looks something like (Pseudo code used to avoid unnecessary information)
variable = FunctionThatReadsFromAFile();
ITransactionManager transactionObject = new TransactionManager();
IDbTransaction dbTransaction = transactionObject.Get();
WriteToFirstTable(variable ,dbTransaction);
WriteToSecondtable(variable ,dbTransaction);
WriteToThirdTable(variable ,dbTransaction);
if(!Error)
transactionObject.Commit(dbTransaction);
else
transactionObject.Rollback(dbTransaction);
Like i said, this works fine for smaller data sets, but when the file has more than a particular amount of rows (dependent on time out) it fails on commit or rollback.
I can't just change the time out to 10,000 seconds for example, in fact due to the way the program is structured I can't change the time out at all beyond for testing purposes. So what i'm trying to do is have the program work on 100 rows at a time instead of the entire file at once, committing them , but rolling back everything if one of the "sets of hundred" fail, I've understood that this can be done with nested transactions, but doing this ;
using (TransactionScope outterTransaction = new TransactionScope())
{
while(file.read())
{
using (TransactionScope innerTransaction = new TransactionScope())
{
variable = GetNextHundredOrLessRows(file); //100 rows at a time basically
WriteToFirstTable(variable ,innerTransaction );
WriteToSecondtable(variable ,innerTransaction );
WriteToThirdTable(variable ,innerTransaction);
if(!Error)
innerTransaction.Complete();
else
innerTransaction.Rollback();
}
}
if(!Error)
outterTransaction.Complete();
else
outterTransaction.Rollback();
}
isn't working, any idea what i'm doing wrong?
Thank you all in advance for taking time to attempt to help me out.
Edit: Also is this the right track to take to solve the issue? I've read that nested transactions join the scope of the outer transaction , so would i still run into the same issue on .Complete?