PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

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?

PrepAway - Latest Free Exam Questions & Answers

A.
string instanceName = Assembly.GetEntryAssembly().FullName;
PerformanceCounter perf = new PerformanceCounter(
“.NET Data Provider for SqlServer”,
“NumberOfReclaimedConnections”, instanceName, true);
int leakedConnections = (int)perf.NextValue();

B.
string instanceName = Assembly.GetEntryAssembly().GetName().Name;
PerformanceCounter perf = new PerformanceCounter(
“.NET Data Provider for SqlServer”,
“NumberOfReclaimedConnections”, instanceName, true);
int leakedConnections = (int)perf.NextValue();

C.
string instanceName = Assembly.GetEntryAssembly().FullName;
PerformanceCounter perf = new PerformanceCounter(
“.NET Data Provider for SqlServer”,
“NumberOfNonPooledConnections”, instanceName, true);
int leakedConnections = (int)perf.NextValue();

D.
string instanceName = Assembly.GetEntryAssembly().GetName().Name;
PerformanceCounter perf = new PerformanceCounter(
“.NET Data Provider for SqlServer”,
“NumberOfNonPooledConnections”, instanceName, true);

int leakedConnections = (int)perf.NextValue();

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)


Leave a Reply