O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

19.4. Speeding Up Data Access to a SQL Server Database Using the SQL Provider

Problem

You want to speed up data access in an application that will always be used with SQL Server.

Solution

Use the SQL Server managed provider instead of the OleDB managed provider for accessing the data in the database.

In the code-behind class for the page, open a connection to a SQL Server database using the SQLConnection class and then use the SqlCommand, SqlDataReader, and SqlDataAdapter objects as required by your application.

To test the SQL provider, we have implemented our example from Recipe 19.3 and replaced the getDataReaderTime and getDataAdapterTime methods in the code-behind with the code shown in Examples 19-10 (VB) and 19-11 (C#). The output of the test is shown in Figure 19-3.

Performance using SQL managed provider output

Figure 19-3. Performance using SQL managed provider output

Discussion

The CLR provides four managed providers for accessing data in a database: SQL, OleDB, ODBC, and Oracle. The OleDB and ODBC providers can be used to access virtually any database—including SQL Server, Access, Oracle, and many others—using an OleDB (or ODBC) layer. OleDB communicates to a data source through the OleDB service component, which provides connection pooling and transaction services, and the OleDB provider for the data source. In contrast, the SQL Server provider uses a proprietary protocol to access SQL Server directly, eliminating the additional ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required