1, the database connection will remain open until SqlDataReader is closed, so when using SqlDataReader, you should call Sqldatareader.close () to close it immediately. 2, a connection can only be used by a SqlDataReader, which is why to close the SqlDataReader as early as possible reasons.
3, after using SqlDataReader, you can display the call in the programDatabase ConnectionThe Close method of the ExecuteReader object closes the connection, or you can pass the CommandBehavior.CloseConnection enumeration variable when calling the Command object's method. This automatically closes the database connection when the Close method of the SqlDataReader is called.
4, use SqlDataReader when possible to use and database field type matching method to obtain the corresponding value, such as for the shape of the field using GetInt32, the character type of the field use GetString. This reduces the additional type conversion operations that are added because of inconsistent types.
5, when using SqlDataReader to get multiple records, if you do not have access to the end of the fetch record to close SqlDataReader, you should first call the Command object's Cancel method, and then call the SqlDataReader Close method. The Cancel method of the Command object makesThe database no longer sends the SqlDataReader data to the caller, and if you do not call this method to shut down SqlDataReader directly, the database sends and SqlDataReader data that is not accessed, such as a long empty data stream to the caller.
6. If you want to get the return value or output parameter of a stored procedure by SqlCommand's ExecuteReader method, you must first call the Close method of SqlDataReader to get the value of the output parameter or the return value.
7. If you use SqlDataReader to return only one record, when you call the command's ExecuteReader method, specify
Commandbehavior.singlerow parameter, the use of this parameter has no effect on SQL Server. NET data provider, but when you use OLE DB. NET data provider, when you specify this parameter , the Dataprivider internally will use the IRow interface instead of using a relatively resource-intensive IRowset interface.
C #. NET uses SqlDataReader note a few----turn