-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Sitaraman
Message 8 in Discussion
Hi Rajesh 1. I agree that "Dim sdrReader as New SqlDataReader()"in VB.Net IDE will
result in System.Data.SqlClient.SqlDataReader.Private overloads Sub New (command as
System.Data.SqlClient.SqlCommand)' is not accessible in this context because it is
Private. which is quite misleading. For quite some time even I thought that the
constructor was private. But fact is that the tool tip is not correctly
phrased(probably wat they mean is "Private to the Assembly" and not the access
modifier keyword "Private" :)) 2. As far as your second point("constructor for
DataReader is overloaded and is private & the Friend Constructor is for the base
class") goes , do note that the base class for SQLDataReader is MarshalByRefObject.
SQLDataReader is declared as follows NotInheritable Public Class SqlDataReader
Inherits MarshalByRefObject
Implements IEnumerable, IDataReader, IDisposable, IDataRecord As
MarshalByRefObject supports no such constructor, the constructor cannot be for base
class. SQLDataReader has only one constructor and it is as i had pointed out last
time. To be precise, In the Friend constructor of the SQLDataReader the following
things happen Sets the Me.Current Records affected to -1 Sets
Me.InternalTables to null Sets some other properties Calls the base
class(MarshalByRefObject) default constructor Sets the Me.Command to the command
object passed as parameter to the constructor Sets more properties like
DataReady etc to false.
Again, Im not explaining the logic flow inside the SQLCommand.executereader()[which
creates the SQLDataReader] for brevity of the post(if someone really needs to know it
i can post it).
I dont think this is documented anywhere as such. So how am I sure of my views.
There are two ways of proving it.
1. Logical Conclusion and Interpretation of the available facts a. Why it cannot
be Singleton Any Singleton class has to conform to 3 things a) Constructor should be
private b) A private Member Variable of the same type as the class should be present
c) A Static method should be provided controlling the instantiation and returning the
instance should be present.Basically this method will return the variable mentioned in
b), after instantiating it in case it is null(will be null, when the method is called
for the first time). Of course u will have all that locking and doubly locking logic
in this method(which is necessary in Java but i believe is no more needed in .Net.)
SQLDataReader has none of this. The executeReader which returns a new instance of
SQLDataReader is an instance method of a different object, i.e. SQLCommand. This
violates every concept mentioned above and therefore SQLDataReader CANNOT be Singleton
implementation. b. Why the constructor cannot be Private and has to be Friend
You cannot create an instance, which means constructor is either friend, protected or
private You cannot inherit from SQLDataReader. So Protected becomes irrelevant. Only
options are friend or private It allows u to use SQLCommand, and SQLCommand is capable
of creating an instance of SQLDataReader. Which means the constructor CANNOT be
Private as SQLCommand is able to instantiate it. So the only thing left out is Friend
and it fits the description, as it does allow the SQLCommand to create a
SQLDataReader(both being in the same assembly) and it does not allow ur class to
create a SQLDataReader(as ur class is in a different assembly) This is a
theorotical explanation. 2. Decompilation of SQLDataReader
Im not sure bout the legal implications/validity(i have even posted a query on this
site for the same), but wat i did was to use the Reflector tool to decompile the
System.Data Assembly and go thru the SQLDataReader and SQLCommand Code itself. Would
appreciate if someone(MS Guys who monitor these posts???) could comment on the legal
implications on using such tools for informational purposes.....
That is why im so sure of it. Hope i got my point across regards, sr
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]