Chris Burgess
Chris Burgess

Reputation: 5835

Advantages of using SQLDataReader over a reader that implements IDatareader?

What are the advantages of using a SQLDataReader as opposed to a reader that just implements IDatareader if I'm using SQL Server >= 2005?

Does the SQLDatareader simply have more functionality to choose from, or are there performance improvements using the SQLDatareader?

Any articles that discuss this would be appreciated.

Thanks!

Chris

Upvotes: 1

Views: 1363

Answers (2)

Johannes Rudolph
Johannes Rudolph

Reputation: 35741

First of all let me correct your misunderstanding: If you're using SQL Server NOT every IDataReader will be able to read data from your MS SQL Server

In the .NET environment (which I assume your question applies to) there are two concrete classes implementing IDataReader that can Access SQL Server. One is SQLDataReader and another one is OleDbDataReader. OleDbDataReader actually relies on the OleDb protocol, which is basically an RDBMS communication protocol.

Using IDataReader in your code will (more or less) make sure you can replace the concrete datareader behind it (e.g. giving you the ability to switch database vendors. Not that I know anyone who successfully did that).

For acessing SQL Server, the specialized SQLDataReader is faster by 115% according this source, because it uses the native sql server protocols (named pipes/tcp/ip). It also supports special SQL Server features such as MARS.

Upvotes: 3

Sonny Boy
Sonny Boy

Reputation: 8016

.HasRows property is the only one I can think of. It's not really necessary though.

Upvotes: 0

Related Questions