天天看点

有关SqlDataReader的性能比较

If you need to retrieve a single row, use one of the following options:

1、 Use stored procedure output parameters.

2、 Use a SqlDataReader object.

        Both options avoid the unnecessary overhead of creating a result set on the server and a DataSet on the client. The relative performance of each approach depends on stress levels and whether or not database connection pooling is enabled.

        When database connection pooling is enabled, performance tests have shown the stored procedure approach to outperform the SqlDataReader approach by nearly 30 percent under high-stress conditions (200+ simultaneous connections).

        With connection pooling disabled, the SqlDataReader is a good option under all stress conditions; performance tests have shown it to outperform the stored procedure approach by around 20 percent at 200 browser connections.

Consider the following options when you retrieve a single item of data from a data source:

1、 Use the ExecuteScalar method of a SqlCommand object with a stored procedure.

2、 Use a stored procedure output or return parameter.

3、 Use a SqlDataReader object.

        The ExecuteScalar method returns the data item directly because it is designed for queries that only return a single value. It requires less code than either the stored procedure output parameter or SqlDataReader approaches require..

From a performance perspective, you should use a stored procedure output or return parameter because tests have shown that the stored procedure approach offers consistent performance across low and high-stress conditions (from fewer than 100 simultaneous browser connections to 200 browser connections).

转载于:https://www.cnblogs.com/mist/archive/2004/04/29/8048.html