Attention: We are retiring the ASP.NET Community Blogs. Learn more >

SqlDataReader.Dispose( [I think]true ) ;

I've finally started doing some application development again (it's been a while), and had to construct a bunch of DataTier methods and classes.  I did lots of data access but, one of the things that I noticed was that I didn't use a single data reader!  Maybe I'm missing something, and maybe (likely) I've just constructed a poor app. but, I just couldn't think of a single place to use one.

I wonder how often those things do get used?

7 Comments

  • Try binding a DataSet containing 1000+ records to a DataGrid and see if you want to:

    a) Use custom paging so that you only have to retrieve data pages instead of the whole shebang.

    b) Use a DataReader instead of a DataSet.



    I constructed an ASP.NET app using a DataGrid and a DataSet. It worked well when I only have 30-50 rows in the DataSet. When I got to 940 it added about 30 seconds to my page load time.

  • Hi, Darren: I use DataReaders almost exclusively in ASP.NET development. They're the .NET equivalent of the venerable "firehose" cursor.

  • When you have to fill objects with data, datareaders are very fast and easy to use. When you're using datasets, they're of course not necessary.

  • Same here, for ASP.NET, I use SqlDataReaders for the vast majority of data access...only times where I would use DataSets (or DataTables without DataSets) are where I need to cache the data or serialize / access it via a Web Service.

    SqlDataReaders are really handy but you have to remember that they're connected the whole time you're using them so they're really only suitable for instances where you pull out data, do very little with it and dump it (filling custom objects or just binding on to controls are the most typical for me).

  • Oh, also use DataSets for DataRelations...the most useful and seemingly underused thing about them...

  • I use DataReaders all the time, and generally find them to be lots easier than DataSets. They are lightweight (relatively speaking) and unless I need to bind multiple controls to a single result set (which I could actually overcome if I really wanted to) or things I need to do in a CheckBoxList, I always use DataReaders. If you use a pattern that ensure disposal, all is well.

  • iam trying to dispose DataReader but its giving


    ERROR :Private Sub Dispose(disposing As Boolean)' is not accessible in this context because it is 'Private


    can i get solution for this problem plz

Comments have been disabled for this content.