Microsoft Knowledge Base Email Alertz

KBAlertz.com: The

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 310369 - Last Review: March 9, 2006 - Revision: 1.2

No method in the DataReader object closes its underlying connection

This article was previously published under Q310369

SYMPTOMS

The DataReader object does not include a property to retrieve its underlying connection. Although you can close DataReader and then close the OleDbConnection or SqlConnection object on which DataReader was opened, DataReader does not have a built-in connection.

Thus, if you retrieve a DataReader from a component method, you cannot close the underlying connection. That is, if you retrieve a DataReader object from a component, the DataReader stays connected, and there is no way to disconnect it.

RESOLUTION

To resolve this problem, configure the ExecuteReader method of a SqlCommand or OleDbCommand object so that the DataReader connection is automatically closed when you close the DataReader. If you pass the System.Data.CommandBehavior.CloseConnection flag to the ExecuteReader method, the DataReader connection is closed when the DataReader is closed.

STATUS

This behavior is by design.

For security purposes, a component may not want to expose a connection to unknown code. A malicious user could build an application that uses the connection to compromise data on the server. Thus, the DataReader does not have a property to expose or manipulate its underlying connection.

This contrasts with the ADODB.Recordset object, which does include an ActiveConnection property.

MORE INFORMATION

To pass the System.Data.CommandBehavior.CloseConnection flag to the ExecuteReader method, use the following code when you open the DataReader:
MyDataReader = MyCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
				

REFERENCES

For more information, refer to the following topics in the Microsoft .NET Software Development Kit (SDK) documentation or the Microsoft Visual Studio .NET Online Help documentation:
OleDbCommand.ExecuteReader Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbCommandClassExecuteReaderTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbCommandClassExecuteReaderTopic.asp)

CommandBehavior Enumeration
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataCommandBehaviorClassTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataCommandBehaviorClassTopic.asp)

APPLIES TO
  • Microsoft ADO.NET 2.0
  • Microsoft ADO.NET (included with the .NET Framework)
Keywords: 
kbdatabinding kboracle kbprb kbsqlclient kbsystemdata KB310369
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please