Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 143153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:03:01+00:00 2026-05-11T08:03:01+00:00

If I use something like: using (OdbcConnection conn = new OdbcConnection(….)) { conn.open(); my

  • 0

If I use something like:

using (OdbcConnection conn = new OdbcConnection(....)) {   conn.open();   my commands and sql, etc. } 

Do I have to do a conn.close(); or does the using statement keep me from doing that last call? Does it dispose of everything in the using block? For example, if I called other objects unlrelated would it dipose of those automatically also?

Thank you. I was unclear after reading about using on Microsoft’s site. I want to make sure I don’t have any memory leaks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:03:02+00:00Added an answer on May 11, 2026 at 8:03 am
    1. The using block will dispose of the OdbcConnection.
    2. Normal scope rules work for anything declared inside the using block.
    3. The using block will not clean up any other IDisposable objects. It only cleans up the declared item
      • note that you can nest using blocks, or if the items are the same type, multiple items can be initialized at the same time.

    See the top bit of my other answer for How do I use the using keyword in C# for a little more information.

    I should also mention that you can close (dispose) of the connection as soon as you are done with it to release the resource. The guidelines say that the caller should be able to repeatedly call the dispose method. The using block is essentially just a safety net and allows writing clearer code in most circumstances.


    [Edit] e.g. multiple initialization in a using: initialize more than one object in the same using without having to nest using blocks if the objects are the same type:

    using (Bitmap b1 = new Bitmap('file1'), b2 = new Bitmap('file2'))  { ... } 

    Joel Coehoorn mentioned stacking, which is nesting but omitting the braces, much as you can omit the braces in a for, or if statement. The UI doesn’t reformat with an indent. I’d be curious what the IL looks like.

    using(Bitmap b = new Bitmap('filex')) using(Graphics g = Graphics.FromImage(b)) {  } 

    It is an error to use put different objects in the same using error CS1044: Cannot use more than one type in a for, using, fixed, or declaration statement.

    // error CS1044 using(Bitmap b = new Bitmap('filex'), Graphics g = Graphics.FromImage(b))  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 127k
  • Answers 127k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One very limiting feature of the map interface is you… May 12, 2026 at 5:31 am
  • Editorial Team
    Editorial Team added an answer I ran into the same issue with complex model classes… May 12, 2026 at 5:31 am
  • Editorial Team
    Editorial Team added an answer Thanks David. I'm currently looking at 2 possible solutions, yours… May 12, 2026 at 5:31 am

Related Questions

If I use something like: using (OdbcConnection conn = new OdbcConnection(....)) { conn.open(); my
In my (Win32) application, I am displaying Crystal Reports. I set the login information
I find myself frequently using Python's interpreter to work with databases, files, etc --
In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application,
I have a XML schema that I will need to create Java classes for.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.