nerdexam
Microsoft

70-516 · Question #185

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

The correct answer is D. Insert the following code segment at line 07. One thing you should always do is to make sure your connections are always opened within a using statement. Using statements will ensure that even if your application raises an exception while the connection is open, it will always be closed (returned to the pool) before your…

Implementing Data Access

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 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?

Options

  • AInsert the following code segment at line 04.
  • BInsert the following code segment at line 04.
  • CReplace line 01 with the following code segment.
  • DInsert the following code segment at line 07:

How the community answered

(38 responses)
  • A
    8% (3)
  • B
    3% (1)
  • C
    16% (6)
  • D
    74% (28)

Explanation

One thing you should always do is to make sure your connections are always opened within a using statement. Using statements will ensure that even if your application raises an exception while the connection is open, it will always be closed (returned to the pool) before your request is complete. This is very important, otherwise there could be connection leaks.

Topics

#connection pooling#connection lifecycle#SqlConnection#ADO.NET

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice