PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 05?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET.

You write the following code segment in the application. (Line numbers are included for reference only.)

01 string connString = "server=localhost;database=Store;uid=user;pwd=pass;";
02 SqlConnection conn = new SqlConnection(connString);
03 SqlDependency sqlDep = new SqlDependency();
04 sqlDep.OnChange += new OnChangeEventHandler(sqlDep_OnChange);
05
06 cmd.ExecuteNonQuery();
07 cmd.Connection.Close();

You store order details in a table named Orders in the Store database. You need to ensure that the application receives a notification if an order is inserted or updated in the Orders table.

Which code segment should you insert at line 05?

PrepAway - Latest Free Exam Questions & Answers

A.
SqlCommand cmd = new SqlCommand("SELECT OrderID, Amount, Notes FROM Orders", conn);
sqlDep.AddCommandDependency(cmd);
SqlDependency.Start(connString);

B.
SqlCommand cmd = new SqlCommand("SELECT OrderID, Amount, Notes FROM dbo.Orders", conn);
sqlDep.AddCommandDependency(cmd);
cmd.Connection.Open();
SqlDependency.Start(connString);

C.
SqlCommand cmd = new SqlCommand("SELECT OrderID, Amount, Notes FROM dbo.Orders", conn);
sqlDep.AddCommandDependency(cmd);
SqlDependency.Start(connString);

D.
SqlCommand cmd = new SqlCommand("SELECT OrderID, Amount, Notes FROM Orders", conn);
sqlDep.AddCommandDependency(cmd);
SqlDependency.Start(connString);
cmd.Connection.Open();


Leave a Reply