You create Microsoft Windows-based applications.
You receive the following code segment to review. (Line numbers are included for reference only.)
01 public partial class frmReceivables : Form
02 {
03 private DataSet ds;
04 public frmReceivables()
05 {
06 InitializeComponent();
07 }
08 private void frmReceivables(object sender, EventArgs e)
09 {
10 SqlConnection cn = new SqlConnection(strConnectionString);
11 SqlDataAdapter daInvoices = new SqlDataAdapter(“SELECT * FROM Invoices”, cn);
12 SqlDataAdapter daCustomers = new SqlDataAdapter(“SELECT * FROM Customers”, cn);
13 ds = new DataSet(“Receivables”);
14 daInvoices.Fill(ds);
15 daCustomers.Fill(ds);
16 }
17 }
The strConnectionString variable is pre-populated from the application configuration file. Query statements will remain unchanged throughout the life cycle of the application. Connection pooling is not being used. This code segment accesses a Microsoft SQL Server 2000 database. The ds dataset is bound to a data grid view so that users can view and update data in the database. The code currently compiles correctly and works as intended. You need to enhance performance and reliability for this code.
Which two actions should you recommend? (Each correct answer presents part of the solution. Choose two.)
A.
Use an ODBC DSN instead of a connection string.
B.
Use OleDbDataAdapter objects instead of SqlDataAdapter objects to populate the dataset.
C.
Add a line of code before line 14 to open the database connection.
D.
Add a Try…Catch block and close the connection in the catch block.
E.
Add a Try…Catch…Finally block and close the connection in the Finally block.