473,508 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database connections

My aim is to develop a policy for database connections and commits,
however I do not fully understand these phenomena, and any comment is welcome.
I use postgres with psycopg.

The essence of my program is to do operations on a specific database,
so I need a connection all the time.
The program may run for hours or even days. Why not.

I can start a connection at the beginning of the program, and close it at
the end.
Or I may do it as a class-level instruction in the class that is
responsible for the database operations. So it is executed only once,
at the first import.

But it gives an insecure feeling. Connections may break down, and intruders
may misuse them.
I can test if the connection still exist before I do a real transaction.
How do I test, if not with some dummy execute ?

The alternative is to open and close a connection immediately before
and after each transaction + commit. Is that a too defensive way of life ?

egbert
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
================================================== ======================
Jul 18 '05 #1
1 1192
Egbert Bouwman <eg*********@hccnet.nl> wrote:
...
I use postgres with psycopg.

The essence of my program is to do operations on a specific database,
so I need a connection all the time.
The program may run for hours or even days. Why not.
Sure, quite reasonable.
I can start a connection at the beginning of the program, and close it at
the end.
Or I may do it as a class-level instruction in the class that is
responsible for the database operations. So it is executed only once,
at the first import.
Either makes sense.
But it gives an insecure feeling. Connections may break down, and intruders
may misuse them.
If anybody can hijack an existing connection to a database, inserting
themselves in the middle of an existing conversation, your whole system
is already in such deep dodo that any attempt at amelioratio is doomed.

Sure, connections do break down -- server might be down or whatever.
I can test if the connection still exist before I do a real transaction.
How do I test, if not with some dummy execute ?
Nah! Just be ready to catch the exception you'll get if the server is
down or whatever, and react to such a hopefully-transient failure like
you would to any other (try reopening once, or try periodically forever,
or whatever else is your policy for "server is down or the like").

The alternative is to open and close a connection immediately before
and after each transaction + commit. Is that a too defensive way of life ?


Yes, it is. I don't really see benefits. You still have to be ready to
catch and deal with exceptions for the unlikely but not impossible case
that the server goes down smack in the middle of a transaction -- until
commit succeeds everything is in the air and you must be ready to retry
or whatever. So reuse that readiness to catch the possibility of the
connection having gone down before your transaction started rather than
crashing smack in the middle of it, it's no harder, really.
Alex
Jul 18 '05 #2

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

Similar topics

3
2397
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
2579
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...
3
10274
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
4806
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
1952
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...
7
3674
by: Martin | last post by:
Hello Does anyone know if it is possible to use the smo db.Create() method to create a new sql server database with sql server 2005 express? The debugger complains that remote operations are not...
5
2168
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
3367
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...
8
2820
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is...
9
6258
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
0
7233
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
7135
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
7410
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...
0
7505
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...
0
5650
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,...
1
5060
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...
0
3215
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...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
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...

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.