473,387 Members | 1,379 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,387 software developers and data experts.

Managing Database Connections!

AJ
Hi all,

Just throwing something out to the newsgroup to get a feel for what others
are doing.

I am noticing that with my current coding practice, every time i want to
update a database i generally implement the following pattern.

1) Open db connnection
2) Execute Query
3) Close Db Connection

Having written numerous events / methods that require db access, i am
getting tired of having to manage the Db connection in each routine; ie
create and close a connection like so.

//create db connection
SqlConnection Cn = new
SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);

//open db connection
Cn.Open();

//close db connection
Cn.Close();

Apart from laziness, i have realized when a post back requires a number of
actions I am opening & closing the database numerous times, and wonder how
efficient
it is.

How does everyone else handle their db work.

Does anyone else have a method that allows you to reuse an existing Db
Connection? A singleton class ect???

I am about to add a DAL to an existing 1.1 project....how would ya'll manage
your db connections in their.

Would love any sample code and / or tutorials ?

Input appreciated.

Adam
Sep 5 '06 #1
1 2058
"AJ" <AJ@discussions.microsoft.comwrote in message
news:38**********************************@microsof t.com...
How does everyone else handle their db work.
DAL.
Does anyone else have a method that allows you to reuse an existing Db
Connection?
That's what connection pooling is for. You should always close your database
connection object as soon as possible - so long as the connection string
which was used to open the connection is the same, ADO.NET will reuse it
from the connection pool for you by default...
I am about to add a DAL to an existing 1.1 project....how would ya'll
manage
your db connections in their.

Would love any sample code and / or tutorials ?
Email me privately and I'll happily send you my v1.1 DAL for SQL Server,
together with a class which simulates nullable datatypes - not necessary for
v2...
Sep 5 '06 #2

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

Similar topics

3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
4
by: dustin lee | last post by:
Over the years I've gotten out of the habit of explicitly closing file objects (whether for reading or writing) since the right thing always seems to happen auto-magically (e.g. files get written...
14
by: Nick Gilbert | last post by:
Hi, I have an asp.net application which runs from a CD-ROM using Cassini. As such, it is single user only. The application connects to an Access database when it is loaded, and keeps the same...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
4
by: Sierra | last post by:
Problem: Database connections are not being reused properly. SP_WHO2 shows upwards of 200 connections being created per page request. Most connections exist for 60 seconds then close without...
5
by: John | last post by:
I have an ASP.NET 2.0 application developed in VB.net, that accesses an Microsoft Access database. When the database is on the same IIS server all works just fine. BUT when it tried to access the...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
1
by: Danigan | last post by:
I've often struggled with database calls--not from a coding standpoint, but from the standpoint of how to make them more self-maintaining. My dream would be this: An include file which contains...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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...

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.