PrepAway - Latest Free Exam Questions & Answers

Category: 70-516 (v.2)

Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4 (update October 26th, 2015)

What are two possible code segments that you can use to achieve this goal?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application.
You use the ADO.NET Entity Framework Designer to model entities. The application includes selftracking entities as shown in the following diagram.

There is a Person entity named person1 that has Track Changes turned on.
You need to delete all e-mail addresses that are associated with person1 by using an ObjectContext
named context. What are two possible code segments that you can use to achieve this goal? (Each
correct answer presents a complete solution. Choose two).

Which code segment should you insert at line 06?

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.)
01 Dim customerOrders As New DataSet()
02 customerOrders.EnforceConstraints = True
03 Dim ordersFK As New ForeignKeyConstraint(“ordersFK”,
04 customerOrders.Tables(“Customers”).Columns(“CustomerID”),
05 customerOrders.Tables(“Orders”).Columns(“CustomerID”))
06
07 customerOrders.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?

Which code segment should you insert at line 05?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server database and contains a LINQ to SQL data model. The
data model contains a function named createCustomer that calls a stored procedure. The stored
procedure is also named createCustomer. The createCustomer function has the following signature.
Sub New(customerID As Guid, customerName As [String], address1 As [String])
End Sub
The application contains the following the following code segment. (Line numbers are included for
reference only.)
01 Dim context As New CustomDataContext()
02 Dim userID As Guid = Guid.NewGuid()
03 Dim address1 As [String] = “1 Main Street”
04 Dim name As [String] = “Marc”
05
You need to use the createCustomer stored procedure to add a customer to the database. Which
code segment should you insert at line 05?

You need to retrieve the identity of the new record

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. You
create a stored procedure to insert a new record in the Categories table according to following code
segment.
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. (Line numbers are included for reference only).
1 Private Shared Sub ReturnIdentity(connectionString As String)
2 Using connection As New SqlConnection(connectionString)
3 Dim adapter As New SqlDataAdapter(“SELECT CategoryID, CategoryName FROM
dbo.Categories”, connection)
4 adapter.InsertCommand = New SqlCommand(“InsertCategory”, connection)
5 adapter.InsertCommand.CommandType = CommandType.StoredProcedure
6 Dim rowcountParameter As SqlParameter =
adapter.InsertCommand.Parameters.Add(“@RowCount”, SqlDbType.Int)
7
8 adapter.InsertCommand.Parameters.Add(“@CategoryName”, SqlDbType.NChar, 15,
“CategoryName”)
9 Dim identityParameter As SqlParameter =
10 adapter.InsertCommand.Parameters.Add(“@Identity”, SqlDbType.Int, 0, “CategoryID”)
11
12 Dim categories As New DataTable()
13 adapter.Fill(categories)
14 Dim categoryRow As DataRow = categories.NewRow()
15 categoryRow(“CategoryName”) = “New Beverages”
16 categories.Rows.Add(categoryRow)

17 adapter.Update(categories)
18 Dim rowCount As Int32 =
19 DirectCast(adapter.InsertCommand.Parameters(“@RowCount”).Value, Int32)
20 End Using
21 End Sub
You need to retrieve the identity of the new record. You also need to retrieve the row count. What
should you do?

You need to ensure that the function verifies that customers have no outstanding orders before they are marked

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application connects to a Microsoft SQL Server 2008 database. The application uses DataContexts to
query the database. You create a function that meets the following requirements:
• Updates the Customer table on the database when a customer is marked as deleted
• Updates the related entries in other tables (CustomerAddress, CustomerContacts) by marking
them as deleted
• Prevents consumer code from setting the Deleted columns value directly

You need to ensure that the function verifies that customers have no outstanding orders before they
are marked as deleted. You also need to ensure that existing applications can use the updated
function without requiring changes in the code. What should you do?

Which IsolationLevel should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application
that connects to a Microsoft SQL Server 2008 database. The application performs a database query
within a transaction. You need to ensure that the application can read data that has not yet been
committed by other transactions. Which IsolationLevel should you use?

Which code segment should you insert at line 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.)
01 Using context As New AdventureWorksEntities()
02 Dim orders As ObjectQuery(Of SalesOrderHeader) =
03 context.SalesOrderHeader.Where(“it.CreditCardApprovalCode IS NULL”).Top(“100”)
04 For Each order As SalesOrderHeader In orders
05 order.Status = 4
06 Next
07 Try
08 context.SaveChanges()
09 Catch generatedExceptionName As OptimisticConcurrencyException
10
11 End Try
12 End Using
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 10?

You need to ensure that the correct authentication header is present when requests are made by using MyDataSer

You use Microsoft .NET Framework 4 to develop an application that uses WCF Data Services to
retrieve entities. WCF Data Services uses an authentication scheme that requires an HTTP request
that has the following header format.
GET /OData.svc/Products(1)
Authorization: WRAP access_token=”123456789″
The application includes the following code. (Line numbers are included for reference only.)
01 Public Class Program
02
03 Public Sub GetProducts()
04
05 Dim proxy = New MyDataServiceContext()
06
07
08 End Sub
09
10 End Class
You need to ensure that the correct authentication header is present when requests are made by
using MyDataServiceContext. What should you do?

Which code segment should you insert at line 09?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 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 Shared Sub ExecuteDbCommand(connection As DbConnection)
02 If connection <> Nothing Then
03 Using connection
04 Try
05 connection.Open()
06 Dim command As DbCommand = connection.CreateCommand()
07 command.CommandText = “INSERT INTO Categories (CategoryName) VALUES (‘Low Carb’)”
08 command.ExecuteNonQuery()
09
10 Catch ex As Exception
11 Trace.WriteLine(“Exception.Message: ” + ex.Message)
12 End Try
13 End Using
14 End If
15 End Sub
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 09?

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. The application contains the following code segment.
Dim SQL As String = String.Format(
“SELECT * FROM Customer WHERE CompanyName LIKE ‘%{0}%'”,
companyName)
Dim cmd = New SqlCommand(SQL, con)
You need to reduce the vulnerability to SQL injection attacks. Which code segment should you use?


Page 22 of 31« First...10...2021222324...30...Last »