FIX: Thread abort during SqlCommand.ExecuteReader corrupts SqlConnection pool

Article translations Article translations
Article ID: 319345
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

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).

Properties

Article ID: 319345 - Last Review: June 19, 2014 - Revision: 7.0
Keywords: 
kbnosurvey kbarchive kbhotfixserver kbqfe kbbug kbfix kbnetframe100presp2fix kbnetframe100sp2fix KB319345

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com