PrepAway - Latest Free Exam Questions & Answers

Author: seenagape

What should you do?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application contains the following code segment. (Line numbers are included for reference only.)

01 class DataAccessLayer
02 {
03 private static string connString;
04 …
05 …
06 public static DataTable GetDataTable(string command){
07 …
08 …
09 }
10 }

You need to define the connection life cycle of the DataAccessLayer class.
You also need to ensure that the application uses the minimum number of connections to the database.
What should you do?

Which code segment should you insert at line 02?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server database. The application uses the ADO.NET Entity
Framework to model entities. The database includes objects based on the exhibit. (Click the Exhibit button.)

The application includes the following code segment. (Line numbers are included for reference only.)

01 using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities()){
02 …
03 }

You need to retrieve a list of all Products from todays sales orders for a specified customer.
You also need to ensure that the application uses the minimum amount of memory when retrieving the list.
Which code segment should you insert at line 02?

Which line of code should you insert at line 09?

The application populates a DataSet object by using a SqlDataAdapter object.
You use the DataSet object to update the Categories database table in the database. You write the following code segment.
(Line numbers are included for reference only.)

01 SqlDataAdapter dataAdpater = new SqlDataAdapter(“SELECT CategoryID, CategoryName FROM Categories”, connection);
02 SqlCommandBuilder builder = new SqlCommandBuilder(dataAdpater);
03 DataSet ds = new DataSet();
04 dataAdpater.Fill(ds);
05 foreach (DataRow categoryRow in ds.Tables[0].Rows)
06 {
07 if (string.Compare(categoryRow[“CategoryName”].ToString(), searchValue, true) == 0)
08 {
09 …
10 }
11 }
12 dataAdpater.Update(ds);

You need to remove all the records from the Categories database table that match the value of the searchValue variable.
Which line of code should you insert at line 09?

Which code segment should you add?

The database contains a table named Categories. The Categories table has a primary key identity column named CategoryID.
The application inserts new records by using the following stored procedure.

CREATE PROCEDURE dbo.InsertCategory
@CategoryName nvarchar(15),
@Identity int OUT
AS
INSERT INTO Categories (CategoryName) VALUES(@CategoryName)
SET @Identity = SCOPE_IDENTITY()
RETURN @@ROWCOUNT

You write the following code segment.

SqlDataAdapter adapter = new SqlDataAdapter(“SELECT categoryID, CategoryName FROM dbo.Categories”,connection);
adapter.InsertCommand = new SqlCommand(“dbo.InsertCategory”, connection);
adapter.InsertCommand.CommandType = commandType.StoredProcedure;
adapter.InsertCommand.Parameters.Add(new SqlParameter(“@CategoryName”, SqlDbType.NVarChar, 15,”CategoryName”));

You need to retrieve the identity value for the newly created record. Which code segment should you add?

Which approach should you recommend?

An ASP.NET Web application stores data in a Microsoft SQL Server database that runs on a separate server.
The company requires all database access to be performed under the identity of the user that is connected to the application.
The Web application uses integrated security in the database string.
During testing, the Web application is unable to authenticate to the database as the connected user.
You need to design an authentication strategy.
Which approach should you recommend?