DataView vs DataReader

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marina

    #16
    Re: DataView vs DataReader

    I don't know what these sources are doing. It all depends on the purpose and
    design of a system/component.

    "Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
    news:O7mlmq0lEH A.3760@TK2MSFTN GP12.phx.gbl...[color=blue]
    > ACK
    >
    > But this still goes against most sources that I've seen.
    >
    > Greg
    >
    >
    > "Marina" <someone@nospam .com> wrote in message
    > news:u17jte0lEH A.2588@TK2MSFTN GP12.phx.gbl...[color=green]
    > >I don't think a reusable component, should ever return a datareader to[/color][/color]
    its[color=blue][color=green]
    > > consumer. Because, again, you have to rely on the developer using your
    > > component, to remember to close it in a timely fashion - or just to[/color][/color]
    plain[color=blue][color=green]
    > > close it.
    > >
    > > The component should open and close its own connection - so a connection
    > > leak should never come from that component. It should then return the[/color][/color]
    data[color=blue][color=green]
    > > in a datatable or another data structure, and the consumer can then do
    > > with
    > > it whatever is necessary.
    > >
    > > Datareader can be more efficient, etc, etc - but an architecture[/color][/color]
    component[color=blue][color=green]
    > > should be careful or returning them, as again, this can often be a
    > > problem.
    > > You basically have to make sure that developers remember to close the
    > > readers they get - because if not, you will quickly get a connection[/color][/color]
    pool[color=blue][color=green]
    > > is
    > > out of available connections exception. Then you have to go track down
    > > which
    > > part of the code forgot to close the datareader. And believe me, I[/color][/color]
    speak[color=blue][color=green]
    > > of
    > > this from experience.
    > >
    > > "Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
    > > news:ullFF8rlEH A.3608@TK2MSFTN GP09.phx.gbl...[color=darkred]
    > >> A datareader only keeps the connection open (if closed properly, and
    > >> using
    > >> CommandBehavior .CloseConnectio n) as long as it takes to read the data.
    > >> Using a dataadapter to fill a dataset/dataview uses a datareader behind[/color]
    > > the[color=darkred]
    > >> scenes anyways.
    > >>
    > >> Although I haven't look in awhile, wasn't IBuySpy portal built using[/color]
    > > mostly[color=darkred]
    > >> datareaders returned from functions? I would ask around a little more
    > >> before scraping the datareader solution. I always read the datareaders[/color]
    > > where[color=darkred]
    > >> more scalable.
    > >>
    > >> This all sounds wrong to me.
    > >>
    > >> My .02
    > >> Greg
    > >>
    > >>
    > >> "Marina" <someone@nospam .com> wrote in message
    > >> news:OECuJ$qlEH A.712@TK2MSFTNG P09.phx.gbl...
    > >> > DataReaders are meant for operations that involve reading all the[/color][/color][/color]
    data[color=blue][color=green][color=darkred]
    > >> > right
    > >> > away, and closing the reader. This is because the reader maintains[/color][/color][/color]
    an[color=blue][color=green][color=darkred]
    > >> > open
    > >> > connection to the database - a valuable resource. I am not surprised
    > >> > you
    > >> > are
    > >> > seeing this problem.
    > >> >
    > >> > Now, a dataview, has nothing to do with database access itself. It's
    > >> > really
    > >> > the datatable that can be used to place data into from the result of[/color][/color][/color]
    a[color=blue][color=green][color=darkred]
    > >> > query. A dataview is another layer that can be put on top of that, to
    > >> > provide a sorted or filtered view of the data in the underlying[/color][/color][/color]
    table.[color=blue][color=green][color=darkred]
    > >> >
    > >> > I definitely recommend you go ahead and eliminate the datareader.
    > >> > Datareader should never be returned from functions - as this requires[/color]
    > > the[color=darkred]
    > >> > consumer of the function to remember to close the data reader once it
    > >> > is
    > >> > no
    > >> > longer needed. This isn't something anyone should rely on - not to
    > >> > mention,
    > >> > you never know how long the consumer of the function will keep that[/color]
    > > reader[color=darkred]
    > >> > open. It is no wonder you are experiencing all these problems.
    > >> >
    > >> >
    > >> > "Mark" <mark@Z-Zvolution.nZt> wrote in message
    > >> > news:chqfnl$i4j $1@lust.ihug.co .nz...
    > >> >> Hi all, quick question [Please correct me where I am wong ;)], a[/color]
    > > DataView[color=darkred]
    > >> > is
    > >> >> memory resident "view" of data in a data table therefore once
    > >> >> populated
    > >> > you
    > >> >> can close the connection to the database. Garbage collection can[/color][/color][/color]
    then[color=blue][color=green]
    > > be[color=darkred]
    > >> >> used to "clean up" the DataView once it is not referenced and will[/color][/color][/color]
    not[color=blue][color=green][color=darkred]
    > >> >> effect the number of connections to the database.
    > >> >>
    > >> >> A DataReader on the other hand always maintains a connection to the
    > >> > database
    > >> >> and must be explicitly closed (Do not rely on garbage collection).
    > >> >>
    > >> >> Reason I am asking is that I have been give a heap of vb.net code[/color][/color][/color]
    and[color=blue][color=green][color=darkred]
    > >> > there
    > >> >> are numerous functions that return a DataReader (Causing all sorts[/color][/color][/color]
    of[color=blue][color=green]
    > > SQL[color=darkred]
    > >> >> Timeout headaches, maximum connections reached etc). To solve this
    > >> >> problem
    > >> >> in the quickest amount of time I am thinking of replacing the[/color]
    > > DataReaders[color=darkred]
    > >> >> with DataViews so I can explicitly close the Database connection.
    > >> >>
    > >> >> Any other ideas (I would model the database via business objects and
    > >> > return
    > >> >> these but I really do not have the time as we need a "quote" quick[/color]
    > > fix).[color=darkred]
    > >> >>
    > >> >> Thanks
    > >> >> Mark
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>[/color]
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Kevin Spencer

      #17
      Re: DataView vs DataReader

      Maybe you think you know what you meant. A DataReader IS a Data Access layer
      component. And it is reusable.

      --
      HTH,
      Kevin Spencer
      ..Net Developer
      Microsoft MVP
      I get paid good money to
      solve puzzles for a living

      "Marina" <someone@nospam .com> wrote in message
      news:e6tgte2lEH A.948@TK2MSFTNG P12.phx.gbl...[color=blue]
      > I was talking a data access layer component. There's really no need to[/color]
      make[color=blue]
      > rude and sarcastic comments, I think it should have been obvious what I
      > meant.
      >
      > "Kevin Spencer" <kspencer@takem pis.com> wrote in message
      > news:OMaX7Y2lEH A.2020@TK2MSFTN GP09.phx.gbl...[color=green][color=darkred]
      > > > I don't think a reusable component, should ever return a datareader to[/color][/color]
      > its[color=green][color=darkred]
      > > > consumer. Because, again, you have to rely on the developer using your
      > > > component, to remember to close it in a timely fashion - or just to[/color][/color]
      > plain[color=green][color=darkred]
      > > > close it.[/color]
      > >
      > > Hmm, isn't a DataReader a reusable component? Maybe Microsoft exposed a
      > > component that they shouldn't have? Or maybe they know something you[/color]
      > don't?[color=green]
      > >
      > > --
      > > HTH,
      > > Kevin Spencer
      > > .Net Developer
      > > Microsoft MVP
      > > I get paid good money to
      > > solve puzzles for a living
      > >
      > > "Marina" <someone@nospam .com> wrote in message
      > > news:u17jte0lEH A.2588@TK2MSFTN GP12.phx.gbl...[color=darkred]
      > > > I don't think a reusable component, should ever return a datareader to[/color][/color]
      > its[color=green][color=darkred]
      > > > consumer. Because, again, you have to rely on the developer using your
      > > > component, to remember to close it in a timely fashion - or just to[/color][/color]
      > plain[color=green][color=darkred]
      > > > close it.
      > > >
      > > > The component should open and close its own connection - so a[/color][/color][/color]
      connection[color=blue][color=green][color=darkred]
      > > > leak should never come from that component. It should then return the[/color][/color]
      > data[color=green][color=darkred]
      > > > in a datatable or another data structure, and the consumer can then do[/color]
      > > with[color=darkred]
      > > > it whatever is necessary.
      > > >
      > > > Datareader can be more efficient, etc, etc - but an architecture[/color][/color]
      > component[color=green][color=darkred]
      > > > should be careful or returning them, as again, this can often be a[/color]
      > > problem.[color=darkred]
      > > > You basically have to make sure that developers remember to close the
      > > > readers they get - because if not, you will quickly get a connection[/color][/color]
      > pool[color=green]
      > > is[color=darkred]
      > > > out of available connections exception. Then you have to go track down[/color]
      > > which[color=darkred]
      > > > part of the code forgot to close the datareader. And believe me, I[/color][/color]
      > speak[color=green]
      > > of[color=darkred]
      > > > this from experience.
      > > >
      > > > "Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
      > > > news:ullFF8rlEH A.3608@TK2MSFTN GP09.phx.gbl...
      > > > > A datareader only keeps the connection open (if closed properly, and[/color]
      > > using[color=darkred]
      > > > > CommandBehavior .CloseConnectio n) as long as it takes to read the[/color][/color][/color]
      data.[color=blue][color=green][color=darkred]
      > > > > Using a dataadapter to fill a dataset/dataview uses a datareader[/color][/color]
      > behind[color=green][color=darkred]
      > > > the
      > > > > scenes anyways.
      > > > >
      > > > > Although I haven't look in awhile, wasn't IBuySpy portal built using
      > > > mostly
      > > > > datareaders returned from functions? I would ask around a little[/color][/color][/color]
      more[color=blue][color=green][color=darkred]
      > > > > before scraping the datareader solution. I always read the[/color][/color][/color]
      datareaders[color=blue][color=green][color=darkred]
      > > > where
      > > > > more scalable.
      > > > >
      > > > > This all sounds wrong to me.
      > > > >
      > > > > My .02
      > > > > Greg
      > > > >
      > > > >
      > > > > "Marina" <someone@nospam .com> wrote in message
      > > > > news:OECuJ$qlEH A.712@TK2MSFTNG P09.phx.gbl...
      > > > > > DataReaders are meant for operations that involve reading all the[/color][/color]
      > data[color=green][color=darkred]
      > > > > > right
      > > > > > away, and closing the reader. This is because the reader[/color][/color][/color]
      maintains[color=blue]
      > an[color=green][color=darkred]
      > > > > > open
      > > > > > connection to the database - a valuable resource. I am not[/color][/color][/color]
      surprised[color=blue][color=green]
      > > you[color=darkred]
      > > > > > are
      > > > > > seeing this problem.
      > > > > >
      > > > > > Now, a dataview, has nothing to do with database access itself.[/color][/color]
      > It's[color=green][color=darkred]
      > > > > > really
      > > > > > the datatable that can be used to place data into from the result[/color][/color][/color]
      of[color=blue]
      > a[color=green][color=darkred]
      > > > > > query. A dataview is another layer that can be put on top of that,[/color][/color]
      > to[color=green][color=darkred]
      > > > > > provide a sorted or filtered view of the data in the underlying[/color][/color]
      > table.[color=green][color=darkred]
      > > > > >
      > > > > > I definitely recommend you go ahead and eliminate the datareader.
      > > > > > Datareader should never be returned from functions - as this[/color][/color]
      > requires[color=green][color=darkred]
      > > > the
      > > > > > consumer of the function to remember to close the data reader once[/color][/color]
      > it[color=green]
      > > is[color=darkred]
      > > > > > no
      > > > > > longer needed. This isn't something anyone should rely on - not to
      > > > > > mention,
      > > > > > you never know how long the consumer of the function will keep[/color][/color][/color]
      that[color=blue][color=green][color=darkred]
      > > > reader
      > > > > > open. It is no wonder you are experiencing all these problems.
      > > > > >
      > > > > >
      > > > > > "Mark" <mark@Z-Zvolution.nZt> wrote in message
      > > > > > news:chqfnl$i4j $1@lust.ihug.co .nz...
      > > > > >> Hi all, quick question [Please correct me where I am wong ;)], a
      > > > DataView
      > > > > > is
      > > > > >> memory resident "view" of data in a data table therefore once[/color]
      > > populated[color=darkred]
      > > > > > you
      > > > > >> can close the connection to the database. Garbage collection can[/color][/color]
      > then[color=green][color=darkred]
      > > > be
      > > > > >> used to "clean up" the DataView once it is not referenced and[/color][/color][/color]
      will[color=blue][color=green]
      > > not[color=darkred]
      > > > > >> effect the number of connections to the database.
      > > > > >>
      > > > > >> A DataReader on the other hand always maintains a connection to[/color][/color][/color]
      the[color=blue][color=green][color=darkred]
      > > > > > database
      > > > > >> and must be explicitly closed (Do not rely on garbage[/color][/color][/color]
      collection).[color=blue][color=green][color=darkred]
      > > > > >>
      > > > > >> Reason I am asking is that I have been give a heap of vb.net code[/color][/color]
      > and[color=green][color=darkred]
      > > > > > there
      > > > > >> are numerous functions that return a DataReader (Causing all[/color][/color][/color]
      sorts[color=blue]
      > of[color=green][color=darkred]
      > > > SQL
      > > > > >> Timeout headaches, maximum connections reached etc). To solve[/color][/color][/color]
      this[color=blue][color=green][color=darkred]
      > > > > >> problem
      > > > > >> in the quickest amount of time I am thinking of replacing the
      > > > DataReaders
      > > > > >> with DataViews so I can explicitly close the Database connection.
      > > > > >>
      > > > > >> Any other ideas (I would model the database via business objects[/color][/color]
      > and[color=green][color=darkred]
      > > > > > return
      > > > > >> these but I really do not have the time as we need a "quote"[/color][/color][/color]
      quick[color=blue][color=green][color=darkred]
      > > > fix).
      > > > > >>
      > > > > >> Thanks
      > > > > >> Mark
      > > > > >>
      > > > > >>
      > > > > >
      > > > > >
      > > > >
      > > > >
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Cor Ligthert

        #18
        Re: DataView vs DataReader

        Kevin,

        Mostly a quick look at MSDN helps,

        SQLDataReader Class
        Provides a means of reading a forward-only stream of rows from a SQL Server
        database. This class cannot be inherited.



        I hope this helps?

        Cor


        Comment

        • Kevin Spencer

          #19
          Re: DataView vs DataReader

          Helps what?

          --
          Kevin Spencer
          ..Net Developer
          Microsoft MVP
          I get paid good money to
          solve puzzles for a living

          "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
          news:#4EoKR9lEH A.596@TK2MSFTNG P11.phx.gbl...[color=blue]
          > Kevin,
          >
          > Mostly a quick look at MSDN helps,
          >
          > SQLDataReader Class
          > Provides a means of reading a forward-only stream of rows from a SQL[/color]
          Server[color=blue]
          > database. This class cannot be inherited.
          >
          >[/color]
          http://msdn.microsoft.com/library/de...classtopic.asp[color=blue]
          >
          > I hope this helps?
          >
          > Cor
          >
          >[/color]


          Comment

          • Cor Ligthert

            #20
            Re: DataView vs DataReader

            Useless to tell you.
            [color=blue]
            > Helps what?
            >
            > --
            > Kevin Spencer
            > .Net Developer
            > Microsoft MVP
            > I get paid good money to
            > solve puzzles for a living[/color]


            Comment

            • Kevin Spencer

              #21
              Re: DataView vs DataReader

              IOW, you don't know.

              --
              HTH,
              Kevin Spencer
              ..Net Developer
              Microsoft MVP
              I get paid good money to
              solve puzzles for a living

              "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
              news:eIh3bMZmEH A.1712@TK2MSFTN GP09.phx.gbl...[color=blue]
              > Useless to tell you.
              >[color=green]
              > > Helps what?
              > >
              > > --
              > > Kevin Spencer
              > > .Net Developer
              > > Microsoft MVP
              > > I get paid good money to
              > > solve puzzles for a living[/color]
              >
              >[/color]


              Comment

              Working...