473,811 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database Connection clarification

I have just started programming .NET having come from ASP.

We used to create a connection and store it in a session.This meant for each
user logging into the site there was only one connection

Now with ASP.NET using the SqlClient libraries this is not possible (No
doubt for good reasons).

So for each page before I need to access the DB I call
objConnect = new SqlConnection(c onnectionString );

Is this the right way? Is there more overhead or time needed due to the new
connection being made each time?

If someone could clarify it would be greatly appreciated.
Thanks
Jon
Nov 18 '05 #1
3 1282
There's an interesting clarification here that seems to relate to your
question:

http://support.microsoft.com/default...b;en-us;315461

"You should always close the Connection when you are finished using it. This
can be done using either the Close or Dispose methods of the Connection
object. Connections that are not explicitly closed may not be added or
returned to the pool. For example, a connection that has gone out of scope,
but has not been explicitly closed, is returned to the connection pool only
if the maximum pool size has been reached and if the connection is still
valid. "
"Jon Booth" <jo*******@nusy stems.com.au> wrote in message
news:bq******** **@perki.connec t.com.au...
I have just started programming .NET having come from ASP.

We used to create a connection and store it in a session.This meant for each user logging into the site there was only one connection

Now with ASP.NET using the SqlClient libraries this is not possible (No
doubt for good reasons).

So for each page before I need to access the DB I call
objConnect = new SqlConnection(c onnectionString );

Is this the right way? Is there more overhead or time needed due to the new connection being made each time?

If someone could clarify it would be greatly appreciated.
Thanks
Jon

Nov 18 '05 #2
Your syntax looks fine.
ADO.NET has built in connection pooling.
Open your db connection just before you need it, and close it as soon as you
are done with it.
As long as you use the same connection string everywhere the sharing will be
automatic - you will not actually open a new database connection each time
in most cases despite what the syntax suggests. The connections will be
recycled for you.
Purposely keeping connections open or trying to pass them to other pages
will result in inefficient, poorly performing code.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com


"Jon Booth" <jo*******@nusy stems.com.au> wrote in message
news:bq******** **@perki.connec t.com.au...
I have just started programming .NET having come from ASP.

We used to create a connection and store it in a session.This meant for each user logging into the site there was only one connection

Now with ASP.NET using the SqlClient libraries this is not possible (No
doubt for good reasons).

So for each page before I need to access the DB I call
objConnect = new SqlConnection(c onnectionString );

Is this the right way? Is there more overhead or time needed due to the new connection being made each time?

If someone could clarify it would be greatly appreciated.
Thanks
Jon

Nov 18 '05 #3
Excellent thanks for your help. Thats exactly what I wanted to hear.

"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:eL******** ******@TK2MSFTN GP10.phx.gbl...
Your syntax looks fine.
ADO.NET has built in connection pooling.
Open your db connection just before you need it, and close it as soon as you are done with it.
As long as you use the same connection string everywhere the sharing will be automatic - you will not actually open a new database connection each time
in most cases despite what the syntax suggests. The connections will be
recycled for you.
Purposely keeping connections open or trying to pass them to other pages
will result in inefficient, poorly performing code.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com


"Jon Booth" <jo*******@nusy stems.com.au> wrote in message
news:bq******** **@perki.connec t.com.au...
I have just started programming .NET having come from ASP.

We used to create a connection and store it in a session.This meant for

each
user logging into the site there was only one connection

Now with ASP.NET using the SqlClient libraries this is not possible (No
doubt for good reasons).

So for each page before I need to access the DB I call
objConnect = new SqlConnection(c onnectionString );

Is this the right way? Is there more overhead or time needed due to the

new
connection being made each time?

If someone could clarify it would be greatly appreciated.
Thanks
Jon


Nov 18 '05 #4

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

Similar topics

8
7901
by: Kamlesh | last post by:
Hi, How do I know the physical database path of a database. When I goto the DB2INSTANCE users's directory (/home/db2inst1), I see following folders: /db2inst1/NODE0000/SQL00001 /db2inst1/NODE0000/SQL00002 /db2inst1/NODE0000/SQL00003 /db2inst1/NODE0000/SQL00004
11
2441
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a database through Connection.open() method, and I do not use Connection.close() method, will garbage collector collect the connection object just because i am not using it any more. 2) I am using a dataset, in which i make some modifications to the...
2
1216
by: Mark | last post by:
Hi, I don't have a code problem. I have an understanding problem. This is a made up situation that mimics my real situation but it is easier to understand. 1. I call a web method with an account number and retrieve an employee object called employee on computer 1 (user 1). The employee object getFirstName() returns "Michelle". 2. I repeat the process on computer 2 as above for the same account
3
3568
by: reelrave | last post by:
Hello All, I've checked around a little on Google (and this group) and have found info similar to what I'm trying to do (i.e., changes that were made in the BE's tables are not reflected in the FE database) and have heard suggestions using code, etcetera. But I need a bit more clarification please. What I'm doing/have done is this (MS Access 2007, FE stored on WXP clients, BE stored on a W2K3 server):
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9204
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.