70-516 · Question #38
Which one of these samples it the correct way to close the connection using Command Behavior?
The correct answer is B. SqlDataReader rdr = new SqlDataReader(). An alternative to explicitly closing the Connection is to pass CommandBehavior.CloseConnection to the ExecuteReader method to ensure that the associated connection is closed when the DataReader is closed. This is especially useful if you are returning a DataReader from a method…
Question
Which one of these samples it the correct way to close the connection using Command Behavior?
Options
- ASqlDataReader rdr = new SqlDataReader();
- BSqlDataReader rdr = new SqlDataReader();
- CSqlDataReader rdr = new SqlDataReader();
- Dusing (SqlDataReader rdr = new SqlDataReader())
How the community answered
(32 responses)- A13% (4)
- B78% (25)
- C3% (1)
- D6% (2)
Explanation
An alternative to explicitly closing the Connection is to pass CommandBehavior.CloseConnection to the ExecuteReader method to ensure that the associated connection is closed when the DataReader is closed. This is especially useful if you are returning a DataReader from a method and do not have control over the closing of the DataReader or associated connection. When you close the data reader and you use CommandBehavior.CloseConnection-the SQLconnection also closes
Topics
Community Discussion
No community discussion yet for this question.