Transaction Timeout

Mar 31, 2014 at 10:06 PM
Edited Mar 31, 2014 at 10: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.
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)
                ' 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()
                        eachFileInfo.FinalFilePath = _localReceivedPath & "\" & eachFileInfo.FileName
                        fileMgr.Copy(eachFileInfo.TempFilePath, eachFileInfo.FinalFilePath, True)
                End If
                Me.execCmdAsNonQuery("exec dbo.sp_Receive;")
            Catch ex As Exception
                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()
Apr 1, 2014 at 1:16 PM

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.
    <machineSettings maxTimeout=""/>
Hope this helps.

Apr 1, 2014 at 3: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.

Apr 2, 2014 at 3:30 PM
Hi Anil: How long did your operations take before you got the timeout exception?
Apr 7, 2014 at 9: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.

Apr 8, 2014 at 2: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