I am having a problem in a production environment that I am not getting locally.
I am running some LINQ to SQL code in a TransactionScope, as shown below:
using (var scope = new TransactionScope())
{
uploadRepository.SubmitChanges();
result = SubmitFileResult.Succeed();
ScanForNewData(upload);
scope.Complete();
}
ScanForNewData () calls GetSubmittedData (). If an exception occurs in GetSubmitted (), we use Nlog to write the error to the file, database and also send an email:
catch (Exception ex)
{
logger.ErrorException(String.Format("Error reading txt file {0} into correct format", upload.DocumentStore.FileName), ex);
return new UploadGetSubmittedDataResult { Exception = ex, Success = false, Message = String.Format("Error reading txt file {0} into correct format", upload.DocumentStore.FileName) };
}
In ScanForNewData, we call repository.SubmitChanges (). It leads to:
The operation is not valid for transaction status. System.Transactions.TransactionException TransactionException System.Transactions.TransactionException: The operation is not valid for transaction status.
, , , - . DataContext Nlog connectionstring Sql-, , , , ( ) - .
, ?
- SQL , . , ...
- . dev Nlog , TransactionException .