Summary of performance optimization of asp.net (i)

Source: Internet
Author: User
Tags eval first row
Asp.net| Performance | Optimization Recent closure of the project. Collated the project documentation to see the previous markup for performance tuning. For the purpose of discussing with others, to express their views. Welcome to this discussion, if there are errors please correct me. (This article does not involve deep mechanism application and research such as Cahe, just some superficial application and suggestion)

On optimization related to data processing

I. Selection of Sqldataread and datasets

Sqldataread Benefits: Read data very quickly. If you do not need to do a lot of processing for the returned data, it is recommended to use SqlDataReader, which has a much better performance than Datset. Disadvantage: Do not close the connection to the database until the data is read

(SqlDataReader reading data is fast forward.) The SqlDataReader class provides a way to read a data-only stream retrieved from a SQL Server database. It uses SQL Server's native network data transfer format to read data directly from a database connection. DataReader need to be explicit close in time. Timely release of the connection to the data. )

The dataset reads the data out and is slow to exist in memory. Disadvantage: high memory footprint. If you need to do a lot of processing of the returned data with a dataset better can reduce the connection to the database operation. Benefits: Connect to the database only once

* In general, read a large amount of data, do not do a lot of processing of the return data with SqlDataReader. It is more appropriate to datset the return data. The choice of SqlDataReader and dataset depends on the implementation of the program function.



Ii. ExecuteNonQuery and ExecuteScalar

Updates to the data do not need to return the result set, and it is recommended that you use ExecuteNonQuery. Network data transfer can be skipped because the result set is not returned. It simply returns the number of rows affected. ExecuteNonQuery performance is less expensive if you only need to update the data.

ExecuteScalar it returns only the first column of the first row in the result set. Use the ExecuteScalar method to retrieve a single value, such as an ID number, from the database. This operation requires less code than the action required to generate a single value by using the ExecuteReader method.

* Just update the data with ExecuteNonQuery. Single value query using ExecuteScalar

Selection of data binding

Third, the data binding DataBinder

The general binding method <%# DataBinder.Eval (Container.DataItem, "field name")%>

Binding with DataBinder.Eval does not necessarily concern the data source (Dataread or DataSet). You don't have to care about the type of data. Eval converts this data object to a string. A lot of work was done on the bottom bound, using reflective performance. It is easy to use, but it affects the performance of the data.

Take a look at the <%# DataBinder.Eval (Container.DataItem, field name)%>. When the dataset is bound, the DataItem is actually a datarowview (if the binding is a data reader (Dataread) it is a idatarecord. Therefore, the direct conversion to DataRowView, will bring a great performance improvement.

<%# CType (Container.dataitem,datarowview). Row (field name)%>

* The binding of data is recommended to use <%# CType (Container.dataitem,datarowview). Row (field name)%>. The data can be increased hundreds of times times faster when the volume is large. Note 2 when using: 1. Add <%@ Import namespace= "System.Data"%>.2 on the page. Note the case of the field name (to be particularly noted). If inconsistent with the query, in some cases it can lead to slower than <%# DataBinder.Eval (Container.DataItem, field name)%>. If you want to further improve the speed, you can use <%# CType (Container.dataitem,datarowview). Row (0)%> method. But its readability is not high.

The above is the writing of vb.net. In C #: <@% ((DataRowView) container.dataitem) [Field name]%>

The easiest way to view the state of each execution of a page: The Trace property of its page is true to see the details. As shown in figure







The next article will cover: using stored procedures, Query statement optimization, page optimization, control selection, server control optimization


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.