nerdexam
Microsoft

70-516 · Question #272

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

The correct answer is D. Dim cnn As 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 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.) 01Public Shared Function GetDataReader(sql As String) As SqlDataReader 02Dim dr As SqlDataReader = Nothing 04Return dr 05End Function You need to ensure that the following requirements are met:

The SqlDataReader returned by the GetDataReader method can be used to retrieve 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 line 03?

Options

  • AUsing cnn As New SqlConnection(strCnn)
  • BDim cnn As New SqlConnection(strCnn)
  • CDim cnn As New SqlConnection(strCnn)
  • DDim cnn As New SqlConnection(strCnn)

How the community answered

(29 responses)
  • A
    14% (4)
  • B
    7% (2)
  • C
    3% (1)
  • D
    76% (22)

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#connection lifecycle#CloseConnection

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice