PC Review


Reply
Thread Tools Rate Thread

close SqlDataReader

 
 
Ruslan
Guest
Posts: n/a
 
      5th Jul 2005
Hi,

I have the following code:



using (SqlConnection connection = DBConnector.GetConnection())

{

SqlCommand cm = new SqlCommand();



SqlDataReader dr = new SqlDataReader (cm.ExecuteReader());



while (dr.Read())

{

...

}

}



There is no dr.Close() because the "connection" is closed when it is out of
"using". How it important to add dr.Close()?





Thanks,



Ruslan


 
Reply With Quote
 
 
 
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      5th Jul 2005
Do it anyway. Close the DataReader and the Connection in your Finally.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Ruslan" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I have the following code:
>
>
>
> using (SqlConnection connection = DBConnector.GetConnection())
>
> {
>
> SqlCommand cm = new SqlCommand();
>
>
>
> SqlDataReader dr = new SqlDataReader (cm.ExecuteReader());
>
>
>
> while (dr.Read())
>
> {
>
> ...
>
> }
>
> }
>
>
>
> There is no dr.Close() because the "connection" is closed when it is out
> of
> "using". How it important to add dr.Close()?
>
>
>
>
>
> Thanks,
>
>
>
> Ruslan
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SqlDataReader do I need to call close? CKKwan Microsoft ADO .NET 11 15th Sep 2008 02:22 PM
Performance of sqlDataReader.Close() is very bad? =?Utf-8?B?U2FudG9zaA==?= Microsoft ADO .NET 12 18th Apr 2006 01:50 PM
Question on SqlDataReader.Close Microsoft ADO .NET 5 4th May 2005 06:45 AM
SqlDataReader.Close() bug? Chris Gallucci Microsoft ADO .NET 13 2nd Aug 2004 02:47 PM
SqlDataReader Close problem. swtrse Microsoft ADO .NET 1 7th Jul 2003 03:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 PM.