473,569 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

open connections

When I develop a web app, I open and close connections on each page,
executing multiple commands as necessary within the single open connection.
However, I recently ran into a group of people that create a global
connection for their web applications and share it across
sessions/users/pages. Both models "work", but the second method makes me
cringe ... unfortunately I can't seem to put my cringe into words as to why
one should open and close connections locally.

I'd appreciate your feedback.

The reasons I can come up with:
1. Global variables should be avoided in general
2. Why keep a connection open all the time? Close it when it's not in use.
3. Multiple connections could potentially result in better performance for a
large number of concurrent users.

Others?

Thanks in advance!
mark
Nov 15 '05 #1
2 2947
Hi Mark,

In MSDN is clearly stated that you should open your connection at late as
possible and close it as soon as possible.

You should not keep a connection open and use it for all the threads of a
web app, this is TERRIBLE for performance, the simplest example I can think
of is the use of a SqlDataReader, in MSDN you can read :

While the SqlDataReader is in use, the associated SqlConnection is busy
serving the SqlDataReader. While in this state, no other operations can be
performed on the SqlConnection other than closing it. This is the case until
the Close method of the SqlDataReader is called.

In other words only one DataReader can be used the connection, if one page
is using a datareader with that connection all other pages will have to
wait, in other words this solution does not escalate at all !!!
Do as you do now and close the connection at soon as possible!!!

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
The reasons I can come up with:
1. Global variables should be avoided in general
2. Why keep a connection open all the time? Close it when it's not in use. 3. Multiple connections could potentially result in better performance for a large number of concurrent users.

Others?

Thanks in advance!
mark

Nov 15 '05 #2
One reason for leaving the connections open is pooling. You can pool the
connection and one user uses it a time. This works for companies that have
to buy licenses per seat instead of by processor to save money.

"Mark" <mf****@idonotl ikespam.cce.umn .edu> wrote in message
news:OG******** ******@TK2MSFTN GP12.phx.gbl...
When I develop a web app, I open and close connections on each page,
executing multiple commands as necessary within the single open connection.
However, I recently ran into a group of people that create a global
connection for their web applications and share it across
sessions/users/pages. Both models "work", but the second method makes me
cringe ... unfortunately I can't seem to put my cringe into words as to why
one should open and close connections locally.

I'd appreciate your feedback.

The reasons I can come up with:
1. Global variables should be avoided in general
2. Why keep a connection open all the time? Close it when it's not in use.
3. Multiple connections could potentially result in better performance for a
large number of concurrent users.

Others?

Thanks in advance!
mark

Nov 15 '05 #3

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

Similar topics

1
1234
by: Roy | last post by:
Hi all, Is there any tool/utility that identifies not closed connections? Thanks, Roy
1
2283
by: mark | r | last post by:
is there any ASP script that will display a list of all open connections on a shared host im trying to determine if my previous problem with "system resource exceeded" can be resolved by brute force? Mark www.iosilver.co.uk
1
1298
by: csharpbeginner | last post by:
My requirement is a certain database connection should be closed only when the object is unloaded from memory. Is the class destructor a good place to close open database connections? Thanks in advance for your reply.
1
2559
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and close them as early as possible. My requirement is as follows: I'm developing a class library that will be instantiated by a COM component. My class...
1
2553
by: David Teran | last post by:
Hi, is it possible (i am pretty sure) to list the open connections clients have to a particular database and to force close the connection? regards David ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
1
1359
by: mavrick_101 | last post by:
Hi, I have nested repeaters. But the page breaks if I refresh 2 or 3 times. It breaks with the following error message.. "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. " I am using the following...
7
1617
by: Lenard Redwood | last post by:
I'd like to create a simple chat application that will leave the connection open for a minute and then restart the connection to the server to push data. I plan to use temporary .txt files to store messages. My question is how can I do that in PHP 5, what techniques should I do server-side to keep this connection open and how would be the...
5
8529
by: TimSki | last post by:
Hi, We are using a remotely hosted sql serer 2005 db. We connect to it/run queries etc. using sql server management studio express. Is there anyway to view the number of open connections using ssmse, in particular we want to see the number that are being left open ? Thanks in advance
1
2615
by: Raman Pahwa | last post by:
plz tell me how to check the number of open connections in ASP code.
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.