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 7649311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:56:00+00:00 2026-05-31T10:56:00+00:00

Question from certification exam: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework

  • 0

Question from certification exam:

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application.
The application contains the following code segment. (Line numbers are included for reference only.)

01  class DataAccessLayer
02  {
03    private static string connString;
04
05    ...
06    public static DataTable GetDataTable(string command){
07
08      ...
09    }
10  }

You need to define the connection life cycle of the DataAccessLayer class. You also need to ensure that the application uses the minimum number of connections to the database.
What should you do?

[A] Insert the following code segment at line 04.

private static SqlConnection conn = new SqlConnection(connString);
public static void Open(){
  conn.Open();
}
public static void Close(){
  conn.Close();
}

[B] Insert the following code segment at line 04.

private SqlConnection conn = new SqlConnection(connString);
public void Open(){
  conn.Open();
}
public void Close(){
  conn.Close();
}    

[C] Replace line 01 with the following code segment.

class DataAccessLayer : IDisposable 

Insert the following code segment to line 04.

private SqlConnection conn = new SqlConnection(connString);
public void Open(){
  conn.Open();
}
public void Dispose(){
  conn.Close();
}

[D] Insert the following code segment at line 07.

using (SqlConnection conn = new SqlConnection(connString)){
  conn.Open();
}    

Some people are arguing that the correct answer is [D], but from my point of view it is no sense, because the connection is being opened and immediately closed after the “using” block.

Could someone point the correct answer and explain why?

Thanks!!!

  • 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. Editorial Team
    Editorial Team
    2026-05-31T10:56:02+00:00Added an answer on May 31, 2026 at 10:56 am

    None are the correct answer.

    • A-C are wrong because they don’t handle exceptions.
    • C is also wrong because you want to encapsulate the data access from within your method that returns a DataSet. Datasets are disconnected, and there is no indication that you are doi anything that requires the class to hold open connections between method calls, so there is no reason to make the entire class hold a connection. Just do it within each method that makes DB calls.
    • D is close, but wrong. To fix it, add the data access code after the conn.Open() call, inside of the using() {…} block.

    Note: I’m not sure if you didn’t put the data access code after the .Open() call in D. If you assumed that to be understood, then D is actually the correct answer. When the connection is disposed it is released back into the connection pool. The connection pool will help you minimize the # of open connections. If you need to literally close the connections even when they are inactive you need to start looking into configuring your use of Connection Pooling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the mysql certification guide's example questions ... question Will the following SQL statement
I'm writing this question from the standpoint of an ASP.NET application. However I realize
Another noob question from me. I'm trying to create an application that counts, and
I have the following question from a past exam paper: I am struggling to
Simple question from .NET beginner. How to work with colors in console application? VS
Question from beginner. Why code <%= System.DateTime.Now.ToLongDateString() %> is not executed in ASP.NET. Could
This is a question from recent GATE entrance exam. A process executes the code
Super simple question from an ASP newb: I've got an internal-only ASP.NET website I'm
Extened question from In multi thread application how can i redirect stderr & stdout
Simple question from an absolute n00b. I'm trying to create an edit content screen

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.