RE: question on sqldatareaders

Tech-Archive recommends: Fix windows errors by optimizing your registry



yes you have and it is very appreciated.
Thank You
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


"Ladislav Mrnka" wrote:

Hi,
lifetime of all objects is handled internally by .net framework where all
objects are destroyed (and freed from memory) by garbage collector. If you
close data reader you release or resources you needed to run it - in your
case you also close SqlConnection and release all its resources but you
cannot be 100 percent sure where these objects are collected and destroyed by
garbage collector - it will be after these objects go out of scope but you
don't know when. If you do not explicitly close your reader (and connection)
all resources remain allocated until garbage collector destroys SqlDataReader
and SqlConnection instances. This is reason why you should close these
instances as soon as possible to free your resources and make them availible
to your application.

I hope I have explained it correctly.

Regards,
Ladislav

"WebBuilder451" wrote:

all my readers are created this way in a data layer class with the
CommandBehavior.CloseConnection. It was this that i was told would kill the
reader after it want out of scope in the calling routine.
so in the:
Dim rdr As SqlDataReader = lf.fn_getUserInfo(Page.User.Identity.Name)
If rdr.HasRows Then
rdr.Read()
......
......
i need to add a rdr.close() ?
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


"Peter Bromberg [C# MVP]" wrote:

You need to explicitly Close your DataReaders because they hold open
connections. Also, if you intend only to Call the Close method of the reader,
it needs to have been created with CommandBehavior.CloseConnection in order
for that to close the connection as well.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



"WebBuilder451" wrote:

given i have a class with a data reader function that returns a reader with a:
function fn_getUserInfo() as sqlDataReader
...
...
...
Return sqlcmd1.ExecuteReader(Data.CommandBehavior.CloseConnection)
end

and the following code for using this reader:
Dim lf As loginfunctions = New loginfunctions
Dim rdr As SqlDataReader = lf.fn_getUserInfo(Page.User.Identity.Name)
If rdr.HasRows Then
rdr.Read()
...
...
...
end

Do i need to close this reader at the end of execution or will it go away
after it goes out of scope?

Thanks

--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
.



Relevant Pages

  • Re: VB vs C# question (trying to switch languages)
    ... some day i''m gona pay this forum back for all the help i''m getting ... So you'll have to explicitely add this handler as shown in the article I ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: VB vs C# question (trying to switch languages)
    ... some day i''m gona pay this forum back for all the help i''m getting ... "Patrice" wrote: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: find height of a datagrid
    ... some day i''m gona pay this forum back for all the help i''m getting ... And i need to resize the panel to the specific height of the gridview. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: dataadapter update problem, (please help!)
    ... > What value does the HasErrors property on the DataTable have after you run ... >> some day i''m gona pay this forum back for all the help i''m getting ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: NewsGroups vs vBulletin forum
    ... Just like there are crappy news readers, you get your crappy forum ... old nntp reader is busy in the background downloading more ... Canada: 6,760,000 hits ...
    (borland.public.delphi.non-technical)