.NETGURU
connection in session
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.


Cosmo Kramer

Hello,
Hopefully Scott G. could answer this :)

We have created a template that overrides system.web.ui.page, adding
accessors to certian properties.

Each page has access to about 4 session variables that store objects, one of
those objects being the database CONNECTION object. The idea is that the
connection object is a very expensive call, so we stored it in session and
pass it around to functions/members on the page as needed.

#1 Is this crazy?
#2 Since we store the connection object in session, will this prevent
connection object pooling?

Thanks!

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

Reply to this message...
 
    
Fabio Yeon
To answer your questions:

#1: Yes, don't do it. :)
#2: Yes, especially if you're keeping an open connection object in
session state.

What you're suggesting could be very costly, especially if the number of
concurrent users spikes or increases beyond 10-25 or so. Keeping an
open connection object in session state could very easily lead you to
exhaust available connections to the back end, thus at some point
causing your server to seem unavailable.

Creating the connection per request would allow the underlying db
connection layer to pool them, thus the cost of creating the connection
object should be relatively low. That is also most often the best
compromise between performance and resource utilization on the server,
since the pool would grow during high loads and shrink once idle.

There is also the possibility of creating the connection object as an
instance variable in "global.asax". This has the advantage of having
one connection per request pipeline, but has the downside that spikes in
the load to the web server could cause the server, once it goes idle, to
keep lots of un-utilized connections open (not to mention requests NOT
needing a db access would still "tie-up" a connection). You can monitor
both via perfmon: the number of requests pipelines is "ASP.NET
Applications\Pipeline Instance Count" and Sql connections are ".NET
Data\SqlClient: Current # pooled and nonpooled connections." If you
really wish to try this, here's how to do it:

Global.asax:

<%@ ClassName=3D"MyApp" %>
<script language=3D"C#" runat=3D"server">

public SqlConnection dbConnection =3D null;

public void Application_OnStart()
{
dbConnection =3D new SqlConnection("...");
dbConnection.Open();
}

Public void Application_OnEnd()
{
if (dbConnection !=3D null && dbConnection.State =3D=3D
ConnectionState.Open)
{
dbConnection.Close();
dbConnection =3D null;
}
}

Mypage.aspx:

<% SqlCommand myCommand =3D new SqlCommand("select * from Foo",
MyApp.dbConnection);

...etc...
%>

Hope this helps.

-----Original Message-----
From: Cosmo Kramer [mailto:Click here to reveal e-mail address]=20
Sent: Sunday, June 02, 2002 3:00 AM
To: aspngspeed
Subject: [aspngspeed] connection in session

Hello,
Hopefully Scott G. could answer this :)

We have created a template that overrides system.web.ui.page, adding=20
accessors to certian properties.

Each page has access to about 4 session variables that store objects,
one of=20
those objects being the database CONNECTION object. The idea is that
the=20
connection object is a very expensive call, so we stored it in session
and=20
pass it around to functions/members on the page as needed.

#1 Is this crazy?
#2 Since we store the connection object in session, will this prevent=20
connection object pooling?

Thanks!

_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail.=20
http://www.hotmail.com

| [aspngspeed] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngspeed.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
 
System.Data.ConnectionState
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification