SqlDataReader: IDataRecord performance optimizations
SqlDataReader performance tips from Adam Machanic. I agree with almost everything there. It is mostly basic stuff and is also documented by Microsoft but it is still very interesting. The performance tips go mostly for IDataRecord interface methods and properties such as GetXXX and string indexer. There are no numbers there but I bet on up to 25% of performance gain for both cases. I don't speak here about opening the connection tip which should be obvious.
Here are my 2 cents. There are 2 useful features in IDataRecord such as FieldCount property and GetValues method. Speaking of which it can help you copy the reader to memory as fast as possible (using ArrayList for example) and free the connection. This should improve the scalability.
while(reader.Read()) { object[] values = new object[reader.FieldCount]; reader.GetValues(values); ... }
Sunday, April 24, 2005 11:56 PM