Loading ...

Use/Advantage of using CommandBehavior.CloseConnection in ExecuteReader()

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » Use/Advantage of using CommandBehavior.CloseConnection in ExecuteReader()

Use/Advantage of using CommandBehavior.CloseConnection in ExecuteReader()

Posts under the topic: Use/Advantage of using CommandBehavior.CloseConnection in ExecuteReader()

Posted: 6/16/2011

Contributor 2841  points  Contributor
  • Joined on: 11/29/2008
  • Posts: 62

Hi All,

I am little bit confuse about the use of the ExecuteReader()'s overlaod method with enum CommandBehavior.CloseConnection

like if we are using

 using (SqlDataReader reader = command.ExecuteReader()) 
   
{
}
 

in using reader automatically dispose ,then what is use of the Pass CommandBehavior.CloseConnection

 

Thanks

Vijendra



Posted: 6/16/2011

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391
  Answered

Hi Vijendra,

When you use using to automatically dispose the objects inside the using block, so CommandBehavior.CloseConnection may not affect anything. Anyway, sometimes you may use it out of using block when Data Reader is open for reading data, this argument gives the ability once the Data Reader is closed, the associated connection string will be also closed.

So, I see not much use of it when you use using blocks, but it is very nice feature when you perform operations with Data Reader outside using block.

Hope this helps.
Hajan


Posted: 6/16/2011

Contributor 2841  points  Contributor
  • Joined on: 11/29/2008
  • Posts: 62

Thanks Hajan Smile


Page 1 of 1 (3 items)