Microsoft KB Archive/319345

From BetaArchive Wiki
Knowledge Base


FIX: Thread abort during SqlCommand.ExecuteReader corrupts SqlConnection pool

Article ID: 319345

Article Last Modified on 9/27/2005



APPLIES TO

  • Microsoft ADO.NET 1.0



This article was previously published under Q319345

SYMPTOMS

If the following conditions are true:

  • A long running query that uses the SqlClient.SqlCommand.ExecuteReader method in a multithreaded .NET application is aborted.
  • Threads thereafter use the same connection string to try to read data by using SqlClient.SqlCommand.ExecuteReader.

you receive the following error message:

System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.

The call stack may appear as follows:

at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   at System.Data.SqlClient.SqlCommand.ExecuteReader()
                    

CAUSE

When the thread that interacts with the DataReader object is aborted, the connection cannot be cleaned up properly because the SqlClient.SqlConnection.Close method that contains the cleanup code is not called. This leaves the connection in an indeterminate state and eventually causes the connection pool to enter an unusable state.

RESOLUTION

To resolve this problem, obtain the latest service pack for Microsoft .NET Framework. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

318836 How to obtain the latest .NET Framework service pack


The English version of this fix should have the following file attributes or later:

   Date            Version                                 Size              File name     
   --------------------------------------------------------------------
   05-Mar-2002     1.0.3705.211    1,175,552 bytes   System.data.dll
   29-Jan-2002                                  1,831,936 bytes   NDP10U318609.msp
                



STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft .NET Framework Service Pack 2 (SP2).


Additional query words: adonet connection pooling SQL Exception

Keywords: kbbug kbfix kbqfe kbnetframe100presp2fix kbnetframe100sp2fix kbhotfixserver KB319345