1.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create a Windows Forms application. You plan to deploy the application to several shared client computers. You write the following code segment. (Line numbers are included for reference only.)
01Configuration config = ConfigurationManager.OpenExeConfiguration(exeConfigName);
02
03config.Save();
04...
You need to encrypt the connection string stored in the .config file. Which code segment should you insert at line 02?
2.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. You use the ADO.NET Entity Framework to model entities. You write the following code segment. (Line numbers are included for reference only.)
01public partial class SalesOrderDetail : EntityObject
02{
03partial void OnOrderQtyChanging(short value)
04{
05
06{
07...
08}
09}
10}
You need to find out whether the object has a valid ObjectStateEntry instance. Which code segment should you insert at line 05?
3.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create a Windows Communication Foundation (WCF) Data Services service. The service connects to a Microsoft SQL Server 2008 database. The service is hosted by an Internet Information Services (IIS) 6.0 Web server. The application works correctly in the development environment. However, when you connect to the service on the production server, attempting to update or delete an entity results in an error. You need to ensure that you can update and delete entities on the production server. What should you do?
4.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You create a DataSet object in the application. You add two DataTable objects named App_Products and App_Categories to the DataSet. You add the following code segment to populate the DataSet object. (Line numbers are included for reference only.)
01public void Fill(SqlConnection cnx, DataSet ds) {
03var cmd = cnx.CreateCommand();
04cmd.CommandText = "SELECT * FROM dbo.Products; " + "SELECT * FROM dbo.Categories";
05var adapter = new SqlDataAdapter(cmd);
06
07}
You need to ensure that App_Products and App_Categories are populated from the dbo.Products and dbo.Categories database tables. Which code segment should you insert at line 06?
5.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. The application has two DataTable objects that reference the Customers and Orders tables in the database. The application contains the following code segment. (Line numbers are included for reference only.
01DataSet customerOrders = new DataSet();
02customerOrders.EnforceConstraints = true;
03ForeignKeyConstraint ordersFK = new ForeignKeyConstraint("ordersFK",
04customerOrders.Tables["Customers"].Columns["CustomerID"],
05customerOrders.Tables["Orders"].Columns["CustomerID"]);
06
07customerOrders.Tables["Orders"].Constraints.Add(ordersFK);
You need to ensure that an exception is thrown when you attempt to delete Customer records that have related Order records. Which code segment should you insert at line 06?
6.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. The application uses a DataTable named OrderDetailTable that has the following columns: "ID "OrderID "ProductID "Quantity "LineTotal Some records contain a null value in the LineTotal field and 0 in the Quantity field. You write the following code segment. (Line numbers are included for reference only.)
01DataColumn column = new DataColumn("UnitPrice", typeof(double));
02
03OrderDetailTable.Columns.Add(column);
You need to add a calculated DataColumn named UnitPrice to the OrderDetailTable object. You also need to ensure that UnitPrice is set to 0 when it cannot be calculated. Which code segment should you insert at line 02?
7.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. The application uses the following object query to load a product from the database. (Line numbers are included for reference only.)
01using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities())
02{
03ObjectQuery productQuery = advWorksContext.Product.Where("it.ProductID = 900");
04
05}
You need to log the command that the query executes against the data source. Which code segment should you insert at line 04?
8.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create a Windows Forms application. The application connects to a Microsoft SQL Server database. You need to find out whether the application is explicitly closing or disposing SQL connections. Which code segment should you use?
9.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You write the following code segment that executes two commands against the database within a transaction. (Line numbers are included for reference only.)
01using (SqlConnection connection = new SqlConnection(cnnStr)) {
02connection.Open();
03SqlTransaction sqlTran = connection.BeginTransaction();
04SqlCommand command = connection.CreateCommand();
05command.Transaction = sqlTran;
06try {
07command.CommandText = "INSERT INTO Production.ScrapReason(Name) VALUES('Wrong size')";
08command.ExecuteNonQuery();
09command.CommandText = "INSERT INTO Production.ScrapReason(Name) VALUES('Wrong color')";
10command.ExecuteNonQuery();
11
12}
You need to log error information if the transaction fails to commit or roll back. Which code segment should you insert at line 11?
10.
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. You use the ADO.NET Entity Framework to model entities. The application connects to a Microsoft SQL Server database named AdventureWorks. The application includes the following code segment. (Line numbers are included for reference only.)
01using (AdventureWorksEntities context = new AdventureWorksEntities()){
02ObjectQuery orders =
03context.SalesOrderHeader.Where("it.CreditCardApprovalCode IS NULL").Top("100");
04foreach (SalesOrderHeader order in orders){
05order.Status = 4;
06}
07try {
08context.SaveChanges();
09}
10catch (OptimisticConcurrencyException){
11
12}
13}
You need to resolve any concurrency conflict that can occur. You also need to ensure that local changes are persisted to the database. Which code segment should you insert at line 11?