I. Selection of Sqldataread and datasets
Sqldataread Advantage: Read data very quickly. If you do not need to do a lot of processing of the returned data, it is recommended to use SqlDataReader, which has a much better performance than Datset. Disadvantage: Close the connection to the database until the data is read out
(SqlDataReader read data is fast forward.) The SqlDataReader class provides a way to read a forward-only stream of data retrieved from a SQL Server database. It uses the SQL Server native Network data transfer format to read data directly from the database connection. DataReader need to be in time to explicitly close. The connection to the data can be released in a timely manner. )
The dataset reads the data and slows it down in memory. Cons: High memory usage. If you need to do a lot of processing of the returned data with a dataset, you can reduce the connection operation to the database. Pros: Close to database connections with just one connection
* Generally, read large amounts of data, do not do a lot of processing of the returned data with SqlDataReader. It is appropriate to use Datset for large amounts of returned data. The selection of SqlDataReader and datasets depends on the implementation of the program functions.
Ii. ExecuteNonQuery and ExecuteScalar
Updates to the data do not need to return a result set, and ExecuteNonQuery is recommended. The network data transfer is omitted because no result set is returned. It simply returns the number of rows affected. If you only need to update the data with ExecuteNonQuery performance is less expensive.
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 operations that are required to generate a single value by using the ExecuteReader method, which returns data.
* Just update the data with ExecuteNonQuery. Single-value queries using ExecuteScalar data binding selection
Third, the data binding DataBinder
The general binding method with DataBinder.Eval binding does not have to care about the data source (Dataread or DataSet). Do not care about the type of data eval converts the data object to a string. A lot of work was done at the bottom of the binding, using reflective performance. This is because it is easy to use, but it affects data performance. Take a look. When binding to a DataSet, DataItem is actually a datarowview (if it is a data reader (Dataread) it is a idatarecord. Therefore, the direct conversion to DataRowView will bring a significant improvement in performance.
* Recommended use for binding data. Increase the speed by up to hundreds of times times when the volume of data is large. Note the use of 2 aspects: 1. You need to add. 2. Note the case of the field name (pay special attention). If inconsistent with the query, in some cases results in a slower than. If you want to further improve the speed, you can use the method. But its readability is not high.
The above is the vb.net of the wording. In C #: <@% ((DataRowView) Container.DataItem) ["Field name"]%>
The simplest way to view each process state of a page is to view the details with the trace property of its page true.
First, use stored procedures:
1. Performance: Stored procedures provide advanced features that are not available in many standard SQL languages. Its ability to pass parameters and perform logical expressions helps application designers to handle complex tasks. In addition, stored procedures are stored on the local server, reducing the network transmission bandwidth and execution time required to perform the process. (The stored procedure has precompiled the SQL statement, so it executes much faster than executing the SQL statement in the program)
2, program structure: From the scalability of the program, the use of stored procedures will be convenient for future changes. For example, the structure of the database changed, just modify the corresponding storage structure, and the program in the call part. This part does not belong to the scope of this paper, which belongs to the design of program structure. So do not unfold here.
3. Program security: Use stored procedures to avoid SQL injection attacks.
II. Optimization of query statements (for SQL server2000)
Many people write SQL statements only for the purpose, regardless of the efficiency of the SQL statement execution. In this I only provide a way to optimize the table order, (SQL statement optimization and principles will be in my SQL server2000 study notes)
You can use SQL server2000 Query Analyzer to view the execution of a statement for SQL statement execution efficiency.
Optimize table order: SQL Server automatically optimizes connections to tables in general. Example: Select Name,no from a joins B on A. id=b.id join C on c.id=a.id where Name= ' Wang '
Although the a table is listed first in from, then B, and finally C. However, SQL Server may use the C table first. The principle of its selection is that the total amount of data found in other tables can be reduced in relation to the query being limited to a single line or a few rows. In most cases, SQL Server makes the best choice, but if you find that a complex join query is slower than expected, you can use the SET FORCEPLAN statement to force SQL Server to use the table in the order in which the tables appear. As in the example above: Set Forceplan on.......set Forceplan the execution order of the OFF table will be executed in the order you wrote. View the 2 execution efficiencies in Query Analyzer to select the connection order for the table.
* Use SET Forceplan to select Table Join order
Third, the optimization of the page (. aspx)
Primarily for several page properties
1, EnableViewState (view state of the page). If no special requirements are set to false. With ViewState, each object must be serialized into ViewState before being deserialized by the callback, so there is no cost in using ViewState. Minimize the use of objects and, if possible, minimize the number of objects placed in ViewState. The following conditions can basically disable ViewState:
(1) Page control (. ascx)
(2) The page does not pass back to itself.
(3) No event handling for the control is required.
(4) control does not have dynamic or data-bound property values (or is handled in code for each postpack)
ViewState is disabled for individual pages or for each page, as follows: Single page: per page: in Web. config EnableSessionState keep the default value (if the page uses sessionstate it takes resources). enableViewStateMac If there are no special requirements on security, keep the default values.
2. pagelayout. Page layout model. It is recommended to use FlowLayout (the element is added without an absolute positional attribute). Gridlayout (absolute positioning property) because of absolute positioning, will produce more code than FlowLayout, mainly the positioning information of the control.
3. When the project is released, remember to release the debug state of the page.
4, the HTML language optimization. My advice is to master Html/javascript, less with vs.net2003 auto-production code, it will automatically generate some useless HTML code.
5, smart navigation set to True can give users a noticeable performance improvement. When this property is enabled, it has little impact on the client and the server. It can be smart to rinse new parts that need to be rinsed new.
Iv. Selection of controls:
The selection of HTML controls and server controls. The convenient and functional implementation of server controls is unmatched by HTML controls. But it is made at the expense of server-side resources. My personal advice: If the HTML control does not reach the functionality that you want to implement, it is not possible to combine with some scripting languages such as Javascrpt/vbscript. The server control is not selected. After you select a server control, also try to optimize its controls, such as canceling some page states (see Control Optimizations)
Server control selection: mainly for a few common Data control description:
DataGrid: With the most powerful data display control, built-in data modification, deletion, addition, paging and many other practical functions. If you only need to display the data, try not to select the DataGrid (which stores the data in viewstate). And don't use your own paging feature, Microsoft has done a lot of work at the bottom of automatic paging, although it's easy to use, but it's a big performance expense.
DataList: A lot less functionality than the DataGrid. But the customization is much stronger. The unique multi-line data display, has brought us a lot of convenience. The function that the DataGrid can achieve, it basically can realize. So it is recommended to use it.
Repeater: Minimal functionality, but highly customizable. If you only need to display the data, we recommend it. Because of the reduced functionality, the performance of the server is minimized. So, if it's on the data display, I'm basically choosing repeater and then DataList the last DataGrid
* Select HTML controls as much as possible. The functionality that can be implemented on the client is implemented on the client side (mastering JavaScript), reducing the pressure on the server. Data Control Selection Order: Repeater, DataList, DataGrid
Five, server control optimization:
1, Viewstate
The viewstate of the control is basically consistent with the viewstate of the page. Used to hold some state of the control. The processing principle is the same as the viewstate of the page. Interested in how much data can be stored with the DataGrid bound data test under ViewState, the data it holds is basically the same amount of data as the DataGrid displays.
2, Ispostpack
The default is False. Set to True when an event needs to be generated.
The control is optimized to look at your familiarity with this control. The more you know about the workings of the control, the better it will be optimized.
Performance optimization is 32 words can not tell, I write only the tip of the iceberg, performance optimization is the accumulation of the usual experience and the principle of the operation of the process of continuous recognition.
Source: http://blog.csdn.net/jacky4955/article/details/4458254