I have some production code that has worked for a few years and just started encountering errors last week. The errors only occur with a particular process that inserts a bunch of information into the database.
The error I'm getting is: "This SqlTransaction has completed; it is no longer usable" which tells me that the transaction is either being committed or rolled back between the first SubmitChanges and the second SubmitChanges.
Basically the code looks like this:
WithTransaction(db => {
// Do a bunch of stuff - insert, update objects
db.SubmitChanges();
// Do a bunch more stuff
db.SubmitChanges(); // <-- This line is throwing the error.
});
The code for WithTransaction just opens a transaction, does the action indicated, and then closes the transaction in a finally block. (There's also some error handling, but that's not relevant to this issue.
SubmitChanges is just a wrapper for System.Data.Linq.DataContext.SubmitChanges()
My hypothesis is that something is going wrong in the first SubmitChanges() that is causing the transaction to roll back but isn't throwing an error. So I'm wondering if there's a good way for me to debug the earlier SubmitChanges and see if anything is going wrong there.
Or, alternatively, any other ideas for how to debug this error.