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

Opening a Connection

I'm looking at this application I've written and it seems kind of silly how
many times I open and close a connection to the database.

Is there a best practice as far as this is concerned? If I open a connection
in the page load event is there any way I can be sure that its closed off?

Any thoughts are appreciated,

Jason
Nov 18 '05 #1
3 994
You will save yourself from many problems if you close the connection after
every data access operation. It is the recommended practice in ADO.NET.
Put your data access code into try..finally blocks and close the connection
in the finally.

Eliyahu

"Jason MacKenzie" <jm***************@formet.com> wrote in message
news:eY******************@TK2MSFTNGP09.phx.gbl...
I'm looking at this application I've written and it seems kind of silly how many times I open and close a connection to the database.

Is there a best practice as far as this is concerned? If I open a connection in the page load event is there any way I can be sure that its closed off?

Any thoughts are appreciated,

Jason

Nov 18 '05 #2
> Is there a best practice as far as this is concerned? If I open a
connection
in the page load event is there any way I can be sure that its closed off?
The best way to make sure that the connection is closed is to close it. Make
that the only way.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Jason MacKenzie" <jm***************@formet.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl... I'm looking at this application I've written and it seems kind of silly how many times I open and close a connection to the database.

Is there a best practice as far as this is concerned? If I open a connection in the page load event is there any way I can be sure that its closed off?

Any thoughts are appreciated,

Jason

Nov 18 '05 #3
That's what I always do. Just wanted to see if there was a better way.
Thanks guys.
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
You will save yourself from many problems if you close the connection after every data access operation. It is the recommended practice in ADO.NET.
Put your data access code into try..finally blocks and close the connection in the finally.

Eliyahu

"Jason MacKenzie" <jm***************@formet.com> wrote in message
news:eY******************@TK2MSFTNGP09.phx.gbl...
I'm looking at this application I've written and it seems kind of silly

how
many times I open and close a connection to the database.

Is there a best practice as far as this is concerned? If I open a

connection
in the page load event is there any way I can be sure that its closed off?
Any thoughts are appreciated,

Jason


Nov 18 '05 #4

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

Similar topics

0
by: Anja | last post by:
I have installed the new Visual Studio 2003 and implemented the FolderBrowserDialog. Everything works fine, if I open the FolderBrowserDialog before opening a Database Connection. If I open...
0
by: John Winterbottom | last post by:
Does anyone know if this is possible? We are running Access XP with Windows XP Prof.. We have an ADP file we are using to print custom reports for a client. It's opened and conntrolled through...
3
by: Giuseppe D'Elia | last post by:
Hi there, I got a problem using an MS Access database through ASP.NET. After updating my system from .NET Framework 1.0 to 1.1, my existing application gives me the following error when...
5
by: Burton Roberts | last post by:
When using ASP.NET and an OleDBConnection control I get this error on CNN.Open: "The Microsoft Jet database engine cannot open the file 'C:\A2K\Backups\EdsBe2K.mdb'. It is already opened...
5
by: Daves | last post by:
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...
1
by: Bennie Tilma | last post by:
I'm having trouble with opening the python IDLE-program. When I try to start it, it gives an errormessage wich states that it can not make a connection, possibly because of a firewall. However,...
2
by: Macca | last post by:
Hi, I am writing an app that will have a socket server to listen for and process data from 20+ clients. These clients will send data aproximately every 400-500ms. I was wondering if it is...
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...
1
by: LeAnne | last post by:
my application polls a database every X seconds. Some times X = 0.5 seconds (500 milli seconds) The way the code has been written, the SQL connection is opened & closed during every poll. Is...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.