Which code segment should you insert at line 03?

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.)

01 Public Shared Function GetDataReader(sql As String) As SqlDataReader
02 Dim dr As SqlDataReader = Nothing
03
04 Return dr
05 End 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?

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.)

01 Public Shared Function GetDataReader(sql As String) As SqlDataReader
02 Dim dr As SqlDataReader = Nothing
03
04 Return dr
05 End 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?

A.
Using cnn As New SqlConnection(strCnn) Try Dim cmd As New SqlCommand(sql, cnn) cnn.Open() dr = cmd.ExecuteReader() Catch Throw End Try End Using

B.
Dim cnn As New SqlConnection(strCnn) Dim cmd As New SqlCommand(sql, cnn) cnn.Open()
For interactive and self-paced preparation of exam 70-521, try our practice exams.
Practice exams also include self assessment and reporting features! Try dr = cmd.ExecuteReader() Finally cnn.Close() End Try

C.
Dim cnn As New SqlConnection(strCnn) Dim cmd As New SqlCommand(sql, cnn) cnn.Open() Try dr = cmd.ExecuteReader() cnn.Close() Catch Throw End Try

D.
Dim cnn As New SqlConnection(strCnn) Dim cmd As New SqlCommand(sql, cnn) cnn.Open() Try dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) Catch cnn.Close() Throw End Try



Leave a Reply 0

Your email address will not be published. Required fields are marked *