Implementing datareader and Dispose()

D

Dune

I'm trying to implement my own version of a datareader in
vb .net using the following example:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpguide/html/cpcontemplatedatareadervb.asp

I get the following error:

'TestCustomDataReader.CustomSqlDataReader' must
implement 'Overridable Overloads Sub Dispose()' for
interface 'System.IDisposable'.

So I'm wondering...what is the correct way to implement
the Dispose() method?
 
N

news.microsoft.com

Just curious. Why do you feel the need for a custom DataReader?

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
W

William Ryan

I don't see anything wrong with the dispose method if
you've included everything. That's pretty much standard
Dispose Syntax. in the code snippet, Dispose is
implemented so I'm guessing either something didn't get
copy and pasted or something is left out. I hate to beat
this drum, but seeing the code always helps... I know it
might be proprietary, but can you post your
implementation of .Dispose?


IMHO, and I mean very humble on this one, there's nothing
that compelling about that class that I can see. Most of
the stuff that you'd want from a DataReader pretty much
can't be encapsulated easily. RecordsAffected always
returns -1 (that's the only metric I can see worth
having, and by nature, I can't see away around the DR
implementatino)? IsClosed? GetBytes always throws an
exception? GetBytes, GetChars always throws an
exception? My guess is this class is meant to be as an
example, but I don't know that it's worth implementing.

Well, it's always easy to criticize..I know. I guess
just post your dispose and we can figure it out.

P.S. Although I admit I'm biased b/c I read his stuff
religously, if a guy like Vaughn asks why you want to do
something.....there probably isn't a good answer ;-)

Cheers,

Bill
 
W

William \(Bill\) Vaughn

That's not going to be easy (or even possible) if I understand you
correctly. Think of the DataReader as a pipeline to the data engine.When you
execute a query, the engine starts to fill the pipe with the first few rows
of the resultset and then waits for the rows to be accepted by your
application. By "caching" the DataReader you're implying that the connection
stay open and the task on the server remain idle waiting to send the
remaining rows.

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
D

Dune

doh!

you are absolutely right...stuff got lost during copy-and-
paste.

*sigh* sorry peoples...i'll just go and hide in the corner
now...








but on a related note...the Dispose method calls Me.Close
(), inside which i set the Open/Close property for the
datareader to closed. All good so far. However, the
comment for the Close method says "...sample only changes
the state,but an actual implementation would also clean up
any resources used by the operation."

Does this mean going through and calling Dispose() for all
objects that might be hanging round?Is there anything else
that needs to be dealt with?
 
W

William Ryan

Dune:

Please, as someone who has never ever made a mistake in
my entire life (I even hit the bowl on my first attempt
when I was 1 1/2) , promise you'll never make an
oversight again. As a matter of fact, I speak for
everyone on this NG, mistakes and oversights are
absolutely unacceptable (oops, I keep forgetting I'm not
a KPMG consultant).

That's why the NG's are here ;-)....we all make mistakes
and we tend to make the same ones.

Cached DataReaders kind of scare me...but heck, give it a
try and see what happens.

If you need any help at all, let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top