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)
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)- A2% (1)
- B14% (6)
- C7% (3)
- D77% (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
Community Discussion
No community discussion yet for this question.