PC Review


Reply
Thread Tools Rate Thread

Closing a database connection

 
 
Jon
Guest
Posts: n/a
 
      12th Oct 2007
Hello, in the below, would the connection on dbCommand be
automatically closed once the code has left the using statement or is
it better that I close it?

using (DbCommand dbComm = db.GetStoredProcCommand("Es"))
{
some code
}

thank you,

Jon

 
Reply With Quote
 
 
 
 
gnewsgroup
Guest
Posts: n/a
 
      12th Oct 2007
On Oct 12, 7:36 am, Jon <JonMYa...@gmail.com> wrote:
> Hello, in the below, would the connection on dbCommand be
> automatically closed once the code has left the using statement or is
> it better that I close it?
>
> using (DbCommand dbComm = db.GetStoredProcCommand("Es"))
> {
> some code
>
> }
>
> thank you,
>
> Jon


>From the MSDN documentation, it looks like it will be automatically

disposed at the end of the using block. The principle seems to be
this: If the object is an instance of a class that implement the
IDisposable interface, and if it is declared in a using statement,
then it will be automatically disposed when it exits the using block.

In your case, DbCommand does implement the IDisposable interface,
among others, so the answer is yes.

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      12th Oct 2007
"Jon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Hello, in the below, would the connection on dbCommand be
> automatically closed once the code has left the using statement


Yes.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
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
Closing a Database connection id10t error Microsoft VB .NET 7 18th Sep 2009 11:15 PM
Closing Database connection in Window Service during System Shutdown Amit Microsoft ADO .NET 0 28th Jun 2008 11:40 AM
file access error on SQLCE database file after closing connection Dexlex Microsoft Dot NET Compact Framework 1 21st Jul 2006 06:15 AM
Closing connection to linked database ReidarT Microsoft Access Form Coding 1 13th Nov 2005 09:17 PM
Closing database connection. Brent Microsoft ASP .NET 2 3rd Apr 2004 01:17 AM


Features
 

Advertising
 

Newsgroups
 


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