[Free] New Updated (October) Microsoft 70-516 Real Exam 181-190

Ensurepass

aspx

 

QUESTION 181

You use Microsoft .NET Framework 4 to develop an application that connects to a local Microsoft SQL Server 2008 database. The application can access a high-resolution timer.

 

You need to display the elapsed time, in sub-milliseconds (<1 millisecond), that a database query takes to execute.

 

Which code segment should you use?

 

A.

Dim Stare As Integer = Environment.TickCount

command.ExecuteNonQuery()

Dim Elapsed As Integer = (Environment.TickCount) = Start

Console.WriteLine(“Time Elapsed: {0:N3} ms”, Elapsed)

B.

Dim sw As Stopwatch = New Stopwatch() sw.Start()

command.ExecuteNonQuery() su.Stop()

Console.MriteLine(“Time Elapsed: {0:N3} ms”, sw.ElapsedMilliseconds)

C.

Dim sw As Stopwatch = Stopwatch.StartNew() command.ExecuteNonQuery() sw.Stop()

Console.WriteLine(“Time Elapsed: {0:N3> ms”, sw.Elapsed.Totamilliseconds)

D.

Dim Start As DateTime = DateTime.UtcNow command.ExecuteNonQuery()

Dim Elapsed As TimeSpan = DateTime.UtcNow = Start Console.UriteLine(“Time Elapsed:

<0:N3> ms”, Elapsed.Milliseconds)

 

Correct Answer: B

Explanation:

Stopwatch Class

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

 

 

QUESTION 182

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.

 

You need to associate a previously deserialized entity named personl to an object context named model and persist changes to the database.

 

Which code segment should you use?

 

A.

personl.AcceptChanges() model.SaveChanges()

B.

model.People.Attach(personl) model.SaveChanges()

C.

model.AttachTo(“People”, personl) model.SaveChanges()

D.

model.People.ApplyChanges(personl) model.SaveChanges()

 

Correct Answer: C

Explanation:

Cosiderations from Attaching and Detaching objects

http://msdn.microsoft.com/en- us/library/bb896271.aspx

The object that is passed to the Attach method must have a valid EntityKey value. If the object does not have a valid EntityKey value, use the AttachTo method to specify the name of the entity set.

Attach Use the Attach method of ObjectContext where the method accepts a single typed entity parameter.

AttachTo The AttachTo method of ObjectContext accepts two parameters. The first parameter is a string containing the name of the entity set. The second parameter’ type is o

bject and references the entity you want to add. Attach The Attach method of ObjectSet, which is the entity set’ type, accepts a single typed parameter containing the entity to be added to the ObjectSet.

CHAPTER 6 ADO.NET Entity Framework

Lesson 2: Querying and Updating with the Entity Framework Attaching Entities to an ObjectContext(page 437)

Attaching and Detaching objects

http://msdn.microsoft.com/en-us/library/bb896271.aspx

http://msdn.microsoft.com/en-us/library/bb896248(v=vs.90).aspx

http://msdn.microsoft.com/en-us/library/bb896248.aspx

 

 

 

 

 

 

 

 

 

 

 

QUESTION 183

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application.

 

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

 

01 Class DataAccessLayer

 

02 Private Shared connString As String

 

03

 

04 …

 

05 Public Shared Function GetDataTable(command As String) As DataTable

 

06

 

07 …

 

08 End Function

 

09 End Class

 

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?

 

A.

Insert the following code segment at line 03.

Private Shared conn As New SqlConnection(connString)

Public Shared Sub Open()

conn.Open()

End Sub

Public Shared Sub Close()

conn.Close()

End Sub

B.

Insert the following code segment at line 03.

Private conn As New SqlConnection(connString)

Public Sub Open()

conn.Open() End Sub Public Sub Close()

conn.Close()

End Sub

C.

Replace line 01 with the following code segment.

Class DataAccessLayer

Implements IDisposable

Insert the following code segment to line 03.

Private conn As New SqlConnection(connString)

Public Sub Open()

conn.Open()

End Sub

Public Sub Dispose()

conn.Close()

End Sub

D.

Insert the following code segment at line 06.

Using conn As New SqlConnection(connString)

conn.Open()

End Using

 

Correct Answer: D

Explanation:

One thing you should always do is to make sure your connections are always opened within a using statement.

Using statements will ensure that even if your application raises an exception while the connection is open, it will always be closed (returned to the pool) before your request is complete. This is very important, otherwise there could be connection leaks.

 

 

QUESTION 184

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application uses the ADO.NET Entity Framework to model entities.

 

The model includes the entity shown in the following exhibit.

 

clip_image001

 

You need to add a function that returns the number of years since a person was hired.

 

You also need to ensure that the function can be used within LINQ to Entities queries.

 

What should you do?

 

A.

Add the following code fragment to the .edmx file.

<Function Name=”YearsSinceNow” ReturnType=”Edm.Int32″>

<Parameter Name=”date” Type=”Edm.DateTime” />

<DefiningExpression>

Year(CurrentDateTime()) – Year(date)

</DefiningExpression>

</Function>

Add the following function to the entity class definition.

<EdmComplexType(“SchoolModel”, “YearsSinceNow”)> _

Public Shared Function YearsSinceNow([date] As DateTime) As Integer

Throw New NotSupportedException(“Direct calls are not supported.”)

End Function

B.

Add the following code fragment to the .edmx file.

<Function Name=”YearsSinceNow” ReturnType=”Edm.Int32″>

<Parameter Name=”date” Type=”Edm.DateTime” />

<DefiningExpression>

Year(CurrentDateTime()) – Year(date)

</DefiningExpression>

</Function>

Add the following function to the entity class definition.

<EdmFunction(“SchoolModel”, “YearsSinceNow”)> _

Public Shared Function YearsSinceNow([date] As DateTime) As Integer

Throw New NotSupportedException(“Direct calls are not supported.”)

End Function

C.

Add the following code fragment to the .edmx file.

<Function Name=”YearsSinceNow” ReturnType=”Edm.Int32″>

<Parameter Name=”date” Type=”Edm.DateTime” />

</Function>

Add the following function to the entity class definition.

<EdmFunction(“SchoolModel”, “YearsSinceNow”)> _

Public Shared Function YearsSinceNow([date] As DateTime) As Integer

Return Year(CurrentDateTime() – Year([date]))

End Function

D.

Use the Entity Data Model Designer to create a complex property named YearsSinceNow that can be accessed through the LINQ to Entities query at a later time.

 

Correct Answer: B

Explanation:

How to: Call Model-Defined Functions in Queries

http://msdn.microsoft.com/en-us/library/dd456857.aspx

How to: Call Model-Defined Functions as Object Methods

http://msdn.microsoft.com/en-us/library/dd456845.aspx

 

 

QUESTION 185

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?

 

A.

Dim instanceName As String = Assembly.GetEntryAssembly().FullName

Dim perf As New PerformanceCounter(

“.NET Data Provider for SqlServer”,

“NumberOfReclaimedConnections”, instanceName, True)

Dim leakedConnections As Integer = DirectCast(perf.NextValue(), Integer)

B.

Dim instanceName As String = Assembly.GetEntryAssembly().GetName().Name

Dim perf As New PerformanceCounter(

“.NET Data Provider for SqlServer”,

“NumberOfReclaimedConnections”, instanceName, True)

Dim leakedConnections As Integer = DirectCast(perf.NextValue(), Integer)

C.

Dim instanceName As String = Assembly.GetEntryAssembly().FullName

Dim perf As New PerformanceCounter(

“.NET Data Provider for SqlServer”,

“NumberOfNonPooledConnections”, instanceName, True)

Dim leakedConnections As Integer = DirectCast(perf.NextValue(), Integer)

D.

Dim instanceName As String = Assembly.GetEntryAssembly().GetName().Name

Dim perf As New PerformanceCounter(

“.NET Data Provider for SqlServer”,

“NumberOfNonPooledConnections”, instanceName, True)

Dim leakedConnections As Integer = DirectCast(perf.NextValue(), Integer)

 

Correct Answer: A

Explanation:

NumberOfNonPooledConnections The number of active connections that are not pooled. NumberOfReclaimedConnections The number of connections that have been reclaimed through garbage collection where Close or Dispose was not called by the application. Not explicitly closing or disposing connections hurts performance.

Use of ADO.NET performance counters

http://msdn.microsoft.com/en-us/library/ms254503(v=vs.80).aspx

Assembly Class

http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx

 

 

QUESTION 186

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to several SQL Server databases.

 

You create a function that modifies customer records that are stored in multiple databases. All updates for

a given record are performed in a single transaction.

 

You need to ensure that all transactions can be recovered.

 

What should you do?

 

A.

Call the RecoveryComplete method of the TransactionManager class.

B.

Call the Reenlist method of the TransactionManager class.

C.

Call the EnlistDurable method of the Transaction class.

D.

Call the EnlistVolatile method of the Transaction class.

 

Correct Answer: C

Explanation:

Enlisting Resources as Participants in a Transaction

http://msdn.microsoft.com/en-us/library/ms172153.aspx

Implementing a Resource Manager

http://msdn.microsoft.com/en-us/library/ms229975.aspx

Committing a Transaction in Single-Phase and Multi-Phase

http://msdn.microsoft.com/en-us/library/ckawh9ct.aspx

Resource managers with a durable enlistment must be able to perform recovery if they experience a failure.

Implementing a Resource Manager

http://msdn.microsoft.com/en-us/library/ms229975.aspx

TransactionManager.Reenlist() Reenlists a durable participant in a transaction. A resource manager facilitates resolution of durable enlistments in a transaction by reenlisting the transaction participant after resource failure.

Transaction.EnlistVolatile() Enlists a volatile resource manager to participate in a transaction. Volatile resource managers cannot recovery from failure to complete a transaction in which they were participating. For more information on volatile and durable resources, as well as how to enlist a resource, see Implementing A Resource Manager. Transaction.EnlistDurable() Enlists a durable resource manager to participate in a transaction.

TransactionManager.RecoveryComplete() Notifies the transaction manager that a resource manager recovering from failure has finished reenlisting in all unresolved transactions. All durable resource managers should do recovery when they first start up by calling the Reenlist method for each outstanding transaction. Only when all of the reenlistments are done should the resource manager call RecoveryComplete.

TransactionManager.Reenlist() Method

http://msdn.microsoft.com/en-us/library/system.transactions.transactionmanager.reenlist.aspx

Transaction.EnlistVolatile() Method

http://msdn.microsoft.com/en-us/library/system.transactions.transaction.enlistvolatile.aspx

Transaction.EnlistDurable()

http://msdn.microsoft.com/en-us/library/system.transactions.transaction.enlistdurable.aspx

TransactionManager.RecoveryComplete() Method

http://msdn.microsoft.com/en-us/library/system.transactions.transactionmanager.recoverycomplete.aspx

 

 

QUESTION 187

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application uses the ADO.NET Entity Framework to manage customer and related order records.

 

You add a new order for an existing customer.

 

You need to associate the Order entity with the Customer entity.

 

What should you do?

 

A.

Set the Value property of the EntityReference of the Order entity.

B.

Call the Add method on the EntityCollection of the Order entity.

C.

Use the AddObject method of the ObjectContext to add both Order and Customer entities.

D.

Use the Attach method of the ObjectContext to add both Order and Customer entities.

 

Correct Answer: A

Explanation:

Entity Reference (Of Entity) Represents a related end of an association with a multiplicity of zero or one.

 

 

QUESTION 188

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 use the following SQL statement to retrieve an instance of a DataSet object named ds.

 

SELECT CustomerID, CompanyName, ContactName, Address, City

 

FROM dbo.Customers

 

You need to query the DataSet object to retrieve only the rows where the ContactName field is not NULL.

 

Which code segment should you use?

 

A.

from row in ds.Tables(0).AsEnumerable()

where DirectCast(row(“ContactName”), String) IsNot Nothing

select row

B.

from row in ds.Tables(0).AsEnumerable()

where row.Field(Of String)(“ContactName”) IsNot Nothing

select row

C.

from row in ds.Tables(0).AsEnumerable()

where Not row.IsNull(DirectCast(row(“ContactName”), String))

select row

D.

from row in ds.Tables(0).AsEnumerable()

where Not Convert.IsDBNull(row.Field(Of String)(“Region”))

select row

 

Correct Answer: B

< font style="font-size: 10pt" color="#000000">Explanation:

Field<T>(DataRow, String) Provides strongly-typed access to each of the column values in the specified row.

The Field method also supports nullable types.

 

 

QUESTION 189

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 includes a SqlConnection named conn and a SqlCommand named cmd.

 

You need to create a transaction so that database changes will be reverted in the event that an exception is thrown.

 

Which code segment should you use?

 

A.

Dim transaction = conn.BeginTransaction()

cmd.Transaction = transaction

Try

transaction.Commit()

Catch

transaction.Rollback()

End Try

B.

Dim transaction = conn.BeginTransaction()

cmd.Transaction = transaction

Try

transaction.Commit()

Catch

transaction.Dispose()

End Try

C.

Dim transaction = conn.BeginTransaction()

cmd.Transaction = transaction

Try

Catch

transaction.Commit()

End Try

D.

Dim transaction = conn.BeginTransaction()

cmd.Transaction = transaction

Try

transaction.Rollback()

Catch

transaction.Dispose()

End Try

 

Correct Answer: A

 

 

 

QUESTION 190

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.

 

You need to ensure that the application calls a stored procedure that accepts a table- valued parameter.

 

You create a SqlParameter object.

 

What should you do next?

 

A.

Set the SqIDbType of SqlParameter to Udt.

B.

Set the SqIDbType of SqlParameter to Structured. Set the TypeName of SqlParameter to the type name of the table-valued parameter.

C.

Set the ParometerDirection of SqlParameter to Output.

D.

Set the SqIDbType of SqlParameter to Variant.

 

Correct Answer: B

Explanation:

SqlParameter.DbType Gets or sets the SqlDbType of the parameter. SqlParameter.TypeName Gets or sets the type name for a table-valued parameter. SqlDbType.Structured A special data type for specifying structured data contained in table-valued parameters.

Udt A SQL Server 2005 user-defined type (UDT).

 

Spatial types

http://msdn.microsoft.com/en-us/library/ff848797.aspx

Types of Spatial Data

http://msdn.microsoft.com/en-us/library/bb964711.aspx

Free VCE & PDF File for Microsoft 70-516 Real Exam

Instant Access to Free VCE Files: MCSE|MCSA|MCITP…
Instant Access to Free PDF Files: MCSE|MCSA|MCITP…