Re: Implementing a DataReader : where to store the result from DB ?

From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 04/16/04


Date: Fri, 16 Apr 2004 08:54:14 -0400

Hi Craig:

> I was wondering how efficient this could be ... it really doesn't seem to
> be. I mean, an array of array of objects seems to lead to unnecessary type
> casts.

Sure, and Array or Objects would lead to many
type casts but unless you know the types in advance, I don't see any way
around it.

> Also in other .Net providers, I've seen that a DataTable is used to store
> the values retrived from the DB.

Not necessarily. Depends on what you use. A dataset is also used and
sometime nothing is used, for instance, cmd.ExecuteScalar, cmd.ExecuteReader

Datatables are headless and don't have anything to do with a provider nor do
they care. If a provider chooses to use one it can, but it's not
obligatory.

> Moreover, it seems that other .Net providers, does not store the data in
> anyplace and instead they keep a connection open to the database to
retrieve
> the data on demand.

No, not at all. A dataReader needs a persisent open connections, but when
you fill a DataSet/ DataTable with an Adapter, you defitely don't need an
open connection (or want an open connection) after you are done filling
and/or updating your table. The period between fill and update should
definitely have the connection closed barring some compelling reason to do
otherwise.

Remember that ADO.NET has a Connected (cmd.Executexxx) component and a
Disconnected Component (dataadapter.fill)

> So, I see 3 alternatives here, and I'm looking for a general advise.
> Which is the best or more commonly used approach to store the result
comming
> from the database in an IDataReader?

Yes, it's true that DataReaders are used to fill datatables, but that's not
the same as using a DataReader in general. You can iterate a datareader and
load a custom collection just as easily as a datatable, and if that's how
you want to implement your class, you are free to do so. The distinction
and 'commonly used approach' really depends on the architecture of the app
and the requirements. However the connected mode vs. disconnected mode is
generally used b/c it's the one MS implemented and works pretty well in most
cases.

HTH,

Bill

"Craig Kenisston" <craigkenisston@hotmail.com> wrote in message
news:OOoetc1IEHA.520@tk2msftngp13.phx.gbl...
>
> Hi,
>
> I'm working in the implementation of a little .net provider for a
propietary
> database format.
> I've studied the .Net provider sample that is in the vs.net help, as well
as
> other providers a bit.
>
> There is a class in the sample to store the result from the database :
>
>
> public class MaxResultSet
> {
> public struct MetaData
> {
> public string name;
> public Type type;
> public int maxSize;
> }
>
> public int recordsAffected;
> public MetaData[] metaData;
> public object[,] data;
> }
>

>

>

>
>
> Thanks in advance.
>
>



Relevant Pages

  • Can not make a network connection using a local user context. The current user, SMSCCMBootAcct&
    ... NAL- CreatePath, wrong provider: ... NAL- Attempting to release a device connection. ... NAL- A deviceless connection has not yet been made. ...
    (microsoft.public.sms.admin)
  • RE: web parts and a database
    ... service's provider can not correctly establish ... connection to the underlying database. ... services(include membership, rolemanager, profile, personalization ...) ... Are you creating and developing the web project through HTTP/IIS server ...
    (microsoft.public.dotnet.framework.aspnet)
  • ADO.NET 2.0 - ResultSet concerns
    ... Unless you use a DataReader or Command.Executexxx methods. ... So the golden rule is Open your connection Only when you need to and close ... And tell me that Disconnected methodology isn't going to be widely abandoned ... by 1) newbies 2) former ADO users 3) people who still don't like dealing ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Custom membership provider problem
    ... user wizard and someone said I should switch to custom membership provider. ... >>An error has occurred while establishing a connection to the server. ... >>Boolean& failoverDemandDone, String host, String failoverPartner, String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ADO.NET 2.0 - ResultSet concerns
    ... features removed but I think a strong ... >- ADO.NET is billed as a 'disconnected' methodology. ... Unless you use a DataReader or Command.Executexxx methods. ... >So the golden rule is Open your connection Only when you need to and close ...
    (microsoft.public.dotnet.framework.adonet)