nerdexam
Microsoft

70-516 · Question #209

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. You are creating the data layer of the application. You write the following code segment. (Line…

The correct answer is D. SqlConnection cnn = new SqlConnection(strCnn). CommandBehavior.CloseConnection When the command is executed, the associated Connection object is closed when the associated DataReader object is closed. CommandBehavior Enumeration SqlCommand.ExecuteReader Method (CommandBehavior)

Implementing Data Access

Question

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application. You are creating the data layer of the application. You write the following code segment. (Line numbers are included for reference only.) 01 public static SqlDataReader GetDataReader(string sql) 02 { 03 SqlDataReader dr = null; 04 ... 05 return dr; 06 } You need to ensure that the following requirements are met:

  • The SqlDataReader returned by the GetDataReader method can be used to

retreive rows from the database.

  • SQL connections opened within the GetDataReader method will close

when the SqlDataReader is closed. Which code segment should you insert at the line 04?

Options

  • Ausing(SqlConnection cnn = new SqlConnection(strCnn))
  • BSqlConnection cnn = new SqlConnection(strCnn);
  • CSqlConnection cnn = new SqlConnection(strCnn);
  • DSqlConnection cnn = new SqlConnection(strCnn);

How the community answered

(44 responses)
  • A
    2% (1)
  • B
    14% (6)
  • C
    7% (3)
  • D
    77% (34)

Explanation

CommandBehavior.CloseConnection When the command is executed, the associated Connection object is closed when the associated DataReader object is closed. CommandBehavior Enumeration SqlCommand.ExecuteReader Method (CommandBehavior)

Topics

#SqlDataReader#CommandBehavior.CloseConnection#connection lifetime#GetDataReader

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice