473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Opening/closing db connection in global.asax

is it a good or bad practise to use the session_start & session_end for
opening & closing the database connection? I'd thought that on powerful
servers today the time the connection is kept locked should not matter as
scripts (especially .Net!) are now run in milliseconds?
Nov 19 '05 #1
5 5193
Actually, if the connection pooling is turned on, it does not even matter
where the connections are being opened -- since the connections are re-used.
For a good design, create a class that dispenses Connection objects, and you
can use this from anywhere.

public class ConnectionDispenser
{

// Get a new connection object
public SqlConnection GetConnection()
{
}
}

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Daves" <db****@simnet.is> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
is it a good or bad practise to use the session_start & session_end for
opening & closing the database connection? I'd thought that on powerful
servers today the time the connection is kept locked should not matter as
scripts (especially .Net!) are now run in milliseconds?

Nov 19 '05 #2
On Tue, 15 Mar 2005 14:06:08 -0600, Daves <db****@simnet.is> wrote:
is it a good or bad practise to use the session_start & session_end for
opening & closing the database connection? I'd thought that on powerful
servers today the time the connection is kept locked should not matter as
scripts (especially .Net!) are now run in milliseconds?


Bad practice; as discovered elsewhere, these 2 events don't always occur
or if they do, and your session is 20 minutes, then if a user closes their
browser, the connection sits there (open) for another 19+ minutes.

ADO.NET will pool connections for you automatically, so there's no need to
do anything other than open a connection when needed and close as soon as
done.

There are some caveats to consider, though, as illustrated in this article:

http://www.ondotnet.com/pub/a/dotnet.../connpool.html

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #3
I'd discourage this approach as it's unnecessary to keep this resource open
when most of the time you're not using it. In general you should open the
connection when you need it, use it, then close it as soon as possible. By
default (if you're using the SqlServer managed provider) connections are
pooled, so if other requests into your application are connecting to the
DB with the same connection string (same credentials, essentially) then they
piggy-back off of the open connection. Makes for better sharing of the resource
(connection).

-Brock
DevelopMentor
http://staff.develop.com/ballen

is it a good or bad practise to use the session_start & session_end
for opening & closing the database connection? I'd thought that on
powerful servers today the time the connection is kept locked should
not matter as scripts (especially .Net!) are now run in milliseconds?


Nov 19 '05 #4
WJ
The best approach is using MS/DAAB. It manages connection for you
efficiently and bug free.

John

"Daves" <db****@simnet.is> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
is it a good or bad practise to use the session_start & session_end for
opening & closing the database connection? I'd thought that on powerful
servers today the time the connection is kept locked should not matter as
scripts (especially .Net!) are now run in milliseconds?

Nov 19 '05 #5
well the main idea is to make code shorter, it's "noisy" to have all these
open/close lines repeatedly!!

Do you know of any article on this subject? (c#)
"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Actually, if the connection pooling is turned on, it does not even matter
where the connections are being opened -- since the connections are
re-used.
For a good design, create a class that dispenses Connection objects, and
you
can use this from anywhere.

public class ConnectionDispenser
{

// Get a new connection object
public SqlConnection GetConnection()
{
}
}

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Daves" <db****@simnet.is> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
is it a good or bad practise to use the session_start & session_end for
opening & closing the database connection? I'd thought that on powerful
servers today the time the connection is kept locked should not matter as
scripts (especially .Net!) are now run in milliseconds?


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
4
by: arbpen | last post by:
I am concerned about performance. Usually, in a situation where I am not using a global.asa (shared host, etc), I explicitly close the connection at the bottom of the page in a footer, eg:...
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
5
by: djc | last post by:
is it still customary to use web.config and global.asax to store connection strings? For example storing the string in web.config and using application start procedure in global.asax to declare a...
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
4
by: glbdev | last post by:
Hi. I am having an problem connecting to a remote SQL Server. Other applications (using access) are connection to it but I cannot get it to work through ASP.Net. Here is my connection string:...
4
by: kessa | last post by:
Hi Guys, I've recently had a problem with my site displaying a "system resources exceeded" error message ... and whilst searching this site for a solution (which I think I've now found) I came...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.