
Microsoft TS: Accessing Data with Microsoft .NET Framework 4 - 070-516 Exam Questions
QUESTION NO: 1
You use Microsoft Visual Studio 2010 and .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server 2008 database. The application contains the following
code segment.
string SQL = string.Format("SELECT * FROM Customer WHERE CompanyName LIKE '%
{0}%', companyName);
var cmd = new SqlCommand(SQL, con);
You need to reduce the vulnerability to SQL injection attacks. Which code segment should you use?
You use Microsoft Visual Studio 2010 and .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server 2008 database. The application contains the following
code segment.
string SQL = string.Format("SELECT * FROM Customer WHERE CompanyName LIKE '%
{0}%', companyName);
var cmd = new SqlCommand(SQL, con);
You need to reduce the vulnerability to SQL injection attacks. Which code segment should you use?
Correct Answer: C
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 2
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application uses the ADO.NET Entity Framework to model entities.
The application includes a Customer entity along with a CustomerKey property of the Guid type as shown in
the following exhibit:

You discover that when the application adds a new instance of a Customer, calling the SaveChanges
method
results in the following error message: "Server generated keys are only supported for identity columns."
You need to ensure that the application can add new Customer entities. What should you do?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application uses the ADO.NET Entity Framework to model entities.
The application includes a Customer entity along with a CustomerKey property of the Guid type as shown in
the following exhibit:

You discover that when the application adds a new instance of a Customer, calling the SaveChanges
method
results in the following error message: "Server generated keys are only supported for identity columns."
You need to ensure that the application can add new Customer entities. What should you do?
Correct Answer: C
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 3
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. The application includes two
ObjectContext instances named context1 and context2.
You need to persist the changes in both object contexts within a single transaction. Which code segment
should you use?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. The application includes two
ObjectContext instances named context1 and context2.
You need to persist the changes in both object contexts within a single transaction. Which code segment
should you use?
Correct Answer: C
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 4
You use Microsoft .NET Framework 4.0 to develop an application that uses WCF Data Services to persist entities from the following Entity Data Model.

You create a new Blog instance named newBlog and a new Post instance named newPost as shown in the
following code segment.
(Line numbers are included for reference only.)
01 Blog newBlog = new Blog();
02 Post newPost = new Post();
03 ....
04 Uri serviceUri = new Uri("...");
05 BlogsEntities context = new BlogsEntities(serviceUri);
06 ....
You need to ensure that newPost is related to newBlog through the Posts collection property and that
newPost and newBlog are sent to the service.
Which code segment should you insert at line 06?
You use Microsoft .NET Framework 4.0 to develop an application that uses WCF Data Services to persist entities from the following Entity Data Model.

You create a new Blog instance named newBlog and a new Post instance named newPost as shown in the
following code segment.
(Line numbers are included for reference only.)
01 Blog newBlog = new Blog();
02 Post newPost = new Post();
03 ....
04 Uri serviceUri = new Uri("...");
05 BlogsEntities context = new BlogsEntities(serviceUri);
06 ....
You need to ensure that newPost is related to newBlog through the Posts collection property and that
newPost and newBlog are sent to the service.
Which code segment should you insert at line 06?
Correct Answer: B
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 5
You use Microsoft .NET Framework 4 to develop an application that connects to a Microsoft SQL Server
2008 database.
You add the following stored procedure to the database.
CREATE PROCEDURE [dbo].[InsertTag] @Name nvarchar (15)
AS INSERT INTO [dbo].[Tags] (Name) VALUES(@Name) RETURN @@ROWCOUNT
You need to invoke the stored procedure by using an open SqlConnection named conn. Which code segment should you use?
You use Microsoft .NET Framework 4 to develop an application that connects to a Microsoft SQL Server
2008 database.
You add the following stored procedure to the database.
CREATE PROCEDURE [dbo].[InsertTag] @Name nvarchar (15)
AS INSERT INTO [dbo].[Tags] (Name) VALUES(@Name) RETURN @@ROWCOUNT
You need to invoke the stored procedure by using an open SqlConnection named conn. Which code segment should you use?
Correct Answer: D
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 6
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You create a Database Access Layer (DAL) that is database-independent. The DAL includes the following
code segment.
(Line numbers are included for reference only.)
01 static void ExecuteDbCommand(DbConnection connection)
02 {
03 if (connection != null){
04 using (connection){
05 try{
06 connection.Open();
07 DbCommand command = connection.CreateCommand();
08 command.CommandText = "INSERT INTO Categories (CategoryName)
VALUES ('Low Carb')";
09 command.ExecuteNonQuery();
10 }
11 ...
12 catch (Exception ex){
13 Trace.WriteLine("Exception.Message: " + ex.Message);
14 }
15 }
16 }
17 }
You need to log information about any error that occurs during data access.
You also need to log the data provider that accesses the database. Which code segment should you insert
at line 11?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You create a Database Access Layer (DAL) that is database-independent. The DAL includes the following
code segment.
(Line numbers are included for reference only.)
01 static void ExecuteDbCommand(DbConnection connection)
02 {
03 if (connection != null){
04 using (connection){
05 try{
06 connection.Open();
07 DbCommand command = connection.CreateCommand();
08 command.CommandText = "INSERT INTO Categories (CategoryName)
VALUES ('Low Carb')";
09 command.ExecuteNonQuery();
10 }
11 ...
12 catch (Exception ex){
13 Trace.WriteLine("Exception.Message: " + ex.Message);
14 }
15 }
16 }
17 }
You need to log information about any error that occurs during data access.
You also need to log the data provider that accesses the database. Which code segment should you insert
at line 11?
Correct Answer: C
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 7
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 LINQ to SQL model to retrieve data from the database.
The application will not modify retrieved data. You need to ensure that all the requested data is retrieved.
You want to achieve this goal using the minimum amount of resources. What should you do?
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 LINQ to SQL model to retrieve data from the database.
The application will not modify retrieved data. You need to ensure that all the requested data is retrieved.
You want to achieve this goal using the minimum amount of resources. What should you do?
Correct Answer: B
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 8
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application that
connects to a database by using the Entity Framework.
You create an Entity Data Model (EDM) by using the Generate from database wizard for the following
tables.

You need to ensure that the EDM contains an entity type named Employee that contains all of the data from
both tables.
What should you do?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application that
connects to a database by using the Entity Framework.
You create an Entity Data Model (EDM) by using the Generate from database wizard for the following
tables.

You need to ensure that the EDM contains an entity type named Employee that contains all of the data from
both tables.
What should you do?
Correct Answer: D
QUESTION NO: 9
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application. You use the Entity Framework Designer to create the following Entity Data Model.

You write a method named ValidatePostalCode to validate the postal code for the application.
You need to ensure that the ValidatePostalCode method is called before the PostalCode property set
method is completed and before the underlying value has changed.
Which code segment should you place in the entity's partial class?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application. You use the Entity Framework Designer to create the following Entity Data Model.

You write a method named ValidatePostalCode to validate the postal code for the application.
You need to ensure that the ValidatePostalCode method is called before the PostalCode property set
method is completed and before the underlying value has changed.
Which code segment should you place in the entity's partial class?
Correct Answer: C
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 10
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. You retrieve an entity from an object
context.
A different application updates the database. You need to update the entity instance to reflect updated
values in the database.
Which line of code should you use?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. You retrieve an entity from an object
context.
A different application updates the database. You need to update the entity instance to reflect updated
values in the database.
Which line of code should you use?
Correct Answer: B
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 11
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server 2008 database. You add the following store procedure
to the database.
CREATE PROCEDURE GetSalesPeople AS BEGIN
SELECT FirstName, LastName, Suffix, Email, Phone FROM SalesPeople END
You write the following code segment. (Line numbers are included for reference only.)
01 SqlConnection connection = new SqlConnection("...");
02 SqlCommand command = new SqlCommand("GetSalesPeople", connection);
03 command.CommandType = CommandType.StoredProcedure;
04 ...
You need to retreive all of the results from the stored procedure. Which code segment should you insert at line 04?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application connects to a Microsoft SQL Server 2008 database. You add the following store procedure
to the database.
CREATE PROCEDURE GetSalesPeople AS BEGIN
SELECT FirstName, LastName, Suffix, Email, Phone FROM SalesPeople END
You write the following code segment. (Line numbers are included for reference only.)
01 SqlConnection connection = new SqlConnection("...");
02 SqlCommand command = new SqlCommand("GetSalesPeople", connection);
03 command.CommandType = CommandType.StoredProcedure;
04 ...
You need to retreive all of the results from the stored procedure. Which code segment should you insert at line 04?
Correct Answer: A
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 12
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?
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?
Correct Answer: B
QUESTION NO: 13
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You deploy a Windows Communication Foundation (WCF) Data Service to a production server.
The application is hosted by Internet Information Services (IIS).
After deployment, applications that connect to the service receive the following error message:
"The server encountered an error processing the request. See server logs for more details."
You need to ensure that the actual exception data is provided to client computers. What should you do?
You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You deploy a Windows Communication Foundation (WCF) Data Service to a production server.
The application is hosted by Internet Information Services (IIS).
After deployment, applications that connect to the service receive the following error message:
"The server encountered an error processing the request. See server logs for more details."
You need to ensure that the actual exception data is provided to client computers. What should you do?
Correct Answer: B
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 14
You use Microsoft .NET Framework 4.0 to develop an application that uses LINQ to SQL.
The Product entity in the LINQ to SQL model contains a field named Productlmage. The Productlmage field
holds a large amount of binary data.
You need to ensure that the Productlmage field is retrieved from the database only when it is needed by the
application. What should you do?
You use Microsoft .NET Framework 4.0 to develop an application that uses LINQ to SQL.
The Product entity in the LINQ to SQL model contains a field named Productlmage. The Productlmage field
holds a large amount of binary data.
You need to ensure that the Productlmage field is retrieved from the database only when it is needed by the
application. What should you do?
Correct Answer: D
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).




