Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Closing a database connection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon - 12 Oct 2007 12:36 GMT
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
gnewsgroup - 12 Oct 2007 14:49 GMT
> Hello, in the below, would the connection on dbCommand be
> automatically closed once the code has left the using statement or is
[quoted text clipped - 9 lines]
>
> 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.
Mark Rae [MVP] - 12 Oct 2007 17:11 GMT
> Hello, in the below, would the connection on dbCommand be
> automatically closed once the code has left the using statement

Yes.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.