Stefan
Sun Jul 13 11:28:29 CDT 2003
Thanks for your reply Kevin.
(links were good reading)
The connection is closed for each DataReader directly
after im done with it using the Close method of the
DataReader. The Microsoft Data Application Block
that creates the DataReaders in my case adds the
CommandBehavior.CloseConnection.
My ideas on how to minimize connections is this.
My PageInfo class has methods that returns "page
title", "meta data", number of articles, if its published
and so on.
As I see it, I can add a Load() method to all my classes
that reads all information and populates these values
into different properties. That way I only need to make
one database call(perhaps call it from constructor, New
() ).
Doing this, I think I can prevent at least 5-10
connections on each page load to be made.
If the connection is closed everytime after im done with
my DataReader, should I really need to do this?
I have no idea on how to generate my menus, categorys and
so on without using an recursive function.
Any idea on a good aproach?
Btw, thanks for tip on caching. I will look more into
this.
Regards
Stefan Hellberg
>-----Original Message-----
>Stefan,
>
>Datareaders are forward only cursors that tie up a
connection until you
>properly close it. Looking at the error you get and the
description you give
>you are opening loads of connections to the database and
you are NOT closing
>them quickly. 30-80 active connections to a database
from a single page call
>will almost certainly get you in trouble.
>
>Here are a couple of pages for you to look at:
>Q310369 No method in datareader closes its underlying
connection:
>
http://support.microsoft.com/default.aspx?scid=kb%3ben-
us%3b310369
>Especially note
the "System.Data.CommandBehavior.CloseConnection" flag to
>the ExecuteReader method. I expect you are not having
this one
>
>Best practices for ADO.NET
>
http://msdn.microsoft.com/vbasic/using/understanding/data
/default.aspx?pull=/library/en-
us/dnadonet/html/adonetbest.asp
>Take special attention to the section about "Using the
datareader" and how
>it deals with connections
>
>Last but not least have a look at the caching methods
in .net. It looks to
>me that for instance those menu calls are perfect
candidates to be cached in
>your application. This will save you a lot of roundtrips
to the database.
>
>Your suggestion to open a connection once and then open
all datareaders on
>it won't work since only one datareader can be open on a
single connection.
>This appears different from how it worked in ado, but
actually it isn't
>since in ADO a new connection was implicitly created
(and closed) for you to
>accomplish this. ado.net won't do this anymore.
>
>Hope this helps,
>Edwin Kusters
>Hot ITem Informatica
>
>"Stefan Hellberg" <stefanhellberg@hotmail.com> wrote in
message
>news:04b301c34931$6e9c0650$a101280a@phx.gbl...
>> Hello everyone,
>>
>> I have a big problem with my ASP .NET project that I
hope
>> anyone knows something about.
>>
>> Windows 2000
>> SQL Server 2000
>> NET Framework 1.1
>>
>> I get the below exception.
>>
>> ------
>> System.InvalidOperationException:
>>
>> Timeout expired. The timeout period elapsed prior to
>> obtaining a connection from the pool. This may have
>> occurred because all pooled connections were in use and
>> max pool size was reached.
>> ------
>>
>> Im using Microsoft Data Application block to create
>> DataReaders in my business class methods. Im not
>> providing a connection object to the Data Application
>> Block method, instead I provide the connection string
so
>> a connection will be created each time a DataReader is
>> created and closed when I call the DataReaders close
>> method.
>>
>> Some pages makes alot of calls to different business
>> object methods, so lets say a normal number of calls
>> could be 10-20 for each page load. On some pages I also
>> have recursive methods, for example, a menu creation
>> method that calls itself to get child links.
>>
>> If a few recursive methods is used on a page, then alot
>> more connections to the database is made by a single
>> user, probably a total of 30-80.
>>
>> --
>>
>> Is it bad design that each method creates a new
>> connection and closes it?
>> (I thought that with connection pooling it doesnt
really
>> mattered even if this was done many times by a single
>> user)
>>
>> Should I instead redesign so that I create a connection
>> object before any business classes is used and pass
that
>> connection with each call to the Data Application Block
>> and explicity close that connection at the end of my
ASP
>> page when no more business objects are used?
>>
>> Anyone that have any help for me on this?
>>
>> If my approach is wrong, then where is the best place
to
>> create and close a connection?
>>
>> Lighten up my world please :)
>>
>> All help will be very appreciated.
>>
>> Regards
>> Stefan Hellberg
>
>
>.
>