tags:

views:

430

answers:

2

I'm running an SQL query against a mainframe DB2 database using the OdbcDataReader class and ExecuteReader() method. This code is in production and has been running fine for months.

The query normally takes 1-2 minutes to execute. This past Friday, the query encountered a ThreadAbortException. Below is the formatted stack trace. The ApplicationException in the trace is created in my catch block.

In case it is important, the query is run when a client calls a web service method. The web service is hosted in a Windows Service. The web service is hosted in a Windows Service using the soap.tcp protocol.

Any ideas why the TreadAbortException is happening?

Stack trace for 2 exception(s). Root cause at the top.

Exception 2: Thread was being aborted.
System.Threading.ThreadAbortException inside C:\WINDOWS\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll at System.Data.Common.UnsafeNativeMethods.SQLExecDirectW(OdbcStatementHandle StatementHandle, String StatementText, Int32 TextLength) at System.Data.Odbc.OdbcStatementHandle.ExecuteDirect(String commandText) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior) at MyCompany.MyDatabase.GetFolioList(String sqlWhereClause)

Exception 1: Unable to retrieve the folio summary list where STAT_CD='V'.
System.ApplicationException inside D:\Production\DBGateway\bin\MyDatabase.dll at MyCompany.MyDatabase.GetFolioList(String sqlWhereClause) at MyCompany.MyDatabase.<>c__DisplayClass18.b__17() at MyCompany.WebUtilities.WebServiceBase.WebMethodTemplate1 Worker, StringFormatter1 FormatterMethod">T

A: 

It might be possible that your thread was chosen as the victim in a deadlock situation resulting from optimistic locking, though in that case I would have expected the responsible layer to handle it.

ThreadAbortExceptions can be caused by many things, including other applications or the CLR host aborting the thread. Is your code being hosted by another application? (The seminal example would be Sql Server, though that doesn't appear to be the situation in your case.)

Greg D
Thanks for the reply. As mentioned in the question, the thread is being run in a web service hosted in a Windows Service. Kind of strange, but true.
Dean Hill
+1  A: 

Here is the answer to my own question.

When hosting a web service, there is some process monitoring how long a web service call is taking. If a call is taking too long, then it is killed and a ThreadAbortException will occur. The timeout can be increased.

For a WSE3 web service running outside of ASP.NET, e.g. hosted as soap.tcp (like mine), the configuration property is executionTimeoutInSeconds:

<configuration>
  <microsoft.web.services3>
    <messaging>
      <executionTimeoutInSeconds value="360" />
    </messaging>
  </microsoft.web.services3>
</configuration>

For a web service hosted in ASP.NET, the configuration property is executionTimeout:

<configuration>
<system.web>
            <httpRuntime executionTimeout=”360” />
      </system.web>
</configuration
Dean Hill