views:

212

answers:

2

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

A: 

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

Sonny Boy
+1  A: 

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.

Johannes Rudolph
Thanks, Johannes. Why should SQLDataReader be faster?
Gern Blandston
I have updated my post, please see above. Don't hesitate to mark it as answer :-)
Johannes Rudolph