Transaction Timeout

Mar 31, 2014 at 9:06 PM
Edited Mar 31, 2014 at 9:20 PM
Hi All,

I am trying to do parse some files and process the data from each file. If everything goes well then I am completing the transaction. If something goes wrong I want to rollback all the changes. Here is my code which has transaction in it.
Try
Dim fileMgr As New ChinhDo.Transactions.TxFileManager()
Dim transOptions As TransactionOptions = New TransactionOptions()
transOptions.IsolationLevel = Transactions.IsolationLevel.Serializable
transOptions.Timeout = TimeSpan.Parse(ConfigurationManager.AppSettings("TransactionTimeOut"))
'<add key ="TransactionTimeOut" value="0.01:00:00"/>
'This is the timeout I mentioned in my app config.
Using scope As New TransactionScope(TransactionScopeOption.RequiresNew, transOptions)
            Try
                ' Iterating through each file to import data to data base.
                If fileNames IsNot Nothing AndAlso fileNames.Rows.Count > 0 Then
                    For Each row As DataRow In fileNames.Rows
                        Dim eachFileInfo As MyFile = New MyFile
                        eachFileInfo.FileName = row.Item("FileName").ToString()
                        Me.processReceivedFiles(eachFileInfo)
                        eachFileInfo.FinalFilePath = _localReceivedPath & "\" & eachFileInfo.FileName
                        fileMgr.Copy(eachFileInfo.TempFilePath, eachFileInfo.FinalFilePath, True)
                    Next
                End If
                Me.execCmdAsNonQuery("exec dbo.sp_Receive;")
                scope.Complete()
            Catch ex As Exception
                scope.Dispose()               
                Throw ex
            End Try
        End Using
Catch ex As Exception

End Try
When I debug the code the error is occuring at "End Using" command.
It is giving me a transaction timeout error. Can any one help me to fix this issue.

Error Details:
at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
Coordinator
Apr 1, 2014 at 12:16 PM
Hi,

Try setting a specific timeout setting, like this:
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = IsolationLevel.ReadCommitted;
options.Timeout = TimeSpan.FromMinutes(10);
 
using(TransactionScope scope = new 8 TransactionScope(TransactionScopeOption.Required, options))
{...}
Also, verify that you don't have a custom transaction timeout setting in your config files.
<configuration> 
  <system.transactions>
    <machineSettings maxTimeout=""/>
  </system.transactions>
</configuration> 
Hope this helps.

Chinh
Apr 1, 2014 at 2:04 PM
Hi Chinh,

Thanks for your response.
I tried using similar code as you suggested, still having the same issue. I tried below code
            Dim transOptions As TransactionOptions = New TransactionOptions()
            transOptions.IsolationLevel = Transactions.IsolationLevel.Serializable
            transOptions.Timeout = TimeSpan.FromHours(2)
and I did check on all my config files and Machine.Config file for transaction timeout and I did not find any.
Do you have any other suggestions.

Thanks,
Anil
Coordinator
Apr 2, 2014 at 2:30 PM
Hi Anil: How long did your operations take before you got the timeout exception?
Apr 7, 2014 at 8:14 PM
Hi Chinhdo,

I have found the issue which was causing the timeout.
My machine.config I have something called allowExeDefinition="MachineOnly" I changed this to allowExeDefinition="MachineToApplication" and also I added maxTimeout as you suggested. Everything works fine with these two tweaks.

Thanks,
Anil
Coordinator
Apr 8, 2014 at 1:02 PM
Hi Anil: Thanks for the update! Glad you found out the cause. I was also looking into those machine.config changes but you got there first. Chinh