You are creating an ASP.NET application for a company where the data is stored in a Microsoft SQL Server 6.5 database. The application needs to generate accounting summary reports from very large transaction tables that contain millions of rows. To return each summary report as quickly as possible, how should you connect to SQL Server and retrieve the data?

Difficulty: Medium

Correct Answer: Use a SqlConnection to connect to SQL Server and a SqlCommand to execute a stored procedure that returns the summary data

Explanation:


Introduction / Context:
ASP.NET applications commonly access relational data stored in Microsoft SQL Server. When working with very large tables and performance sensitive reporting, it is important to choose the most efficient data access technology and technique. This question asks which combination of connection type and command execution method is best for high performance summary queries in a SQL Server environment.

Given Data / Assumptions:

  • The back end database is Microsoft SQL Server 6.5.
  • The application is built with ASP.NET and Visual Studio .NET.
  • Transaction tables contain millions of rows.
  • The requirement is to generate summary accounting reports quickly.
  • Stored procedures are available or can be created on SQL Server.

Concept / Approach:
For SQL Server, the native .NET data provider System.Data.SqlClient offers the most efficient data access. SqlConnection and SqlCommand are optimized for SQL Server, providing better performance and integration than generic providers such as OleDb. In addition, using stored procedures on SQL Server improves performance through precompiled execution plans, reduced network traffic, and better maintainability. Combining SqlConnection, SqlCommand, and stored procedures is the recommended best practice for high performance reporting queries.

Step-by-Step Solution:
Step 1: Identify that the database is SQL Server, which is best served by the SqlClient provider.Step 2: Recall that SqlConnection is designed specifically for SQL Server connectivity.Step 3: Use SqlCommand to execute stored procedures that encapsulate complex summary logic on the server side.Step 4: Understand that running aggregation and grouping directly on SQL Server reduces data transferred over the network because only summary rows are returned.Step 5: Compare this approach to generic providers, HTTP based access, or COM interop, which add overhead and complexity without performance benefits.
Verification / Alternative check:
Performance benchmarks and Microsoft guidance consistently recommend using the SqlClient provider when connecting to SQL Server from managed code. Stored procedures are also widely recognized as a performant way to encapsulate queries, especially when working with large datasets. Profiling an application that uses SqlConnection and SqlCommand with stored procedures typically shows efficient CPU and network usage compared to alternatives like OleDb or COM based ADODB calls.

Why Other Options Are Wrong:
Option B uses OleDbConnection and OleDbCommand, which are generic and introduce extra translation overhead when talking to SQL Server. Option C, configuring HTTP access and XML templates, introduces unnecessary complexity and may increase latency due to XML formatting. Option D uses COM interop with ADODB, which adds marshaling overhead and is considered legacy compared to native ADO.NET providers. None of these alternatives match the efficiency and simplicity of SqlConnection combined with stored procedures executed by SqlCommand.

Common Pitfalls:
Developers sometimes assume that any provider will perform the same, or they carry over COM based ADODB habits into .NET applications. Others may push business logic into the application layer and fetch huge result sets, rather than summarizing data on the server side. For very large tables, pulling unnecessary rows is expensive. The optimal pattern is to use a SQL Server specific provider and perform aggregation in stored procedures, returning only the required summary rows to ASP.NET.

Final Answer:
The best approach is to use a SqlConnection with a SqlCommand that executes a stored procedure returning the summary data.

More Questions from Microsoft Certification

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion