Re: Making a database connection global
- From: Göran Andersson <guffa@xxxxxxxxx>
- Date: Sun, 14 May 2006 23:59:50 +0200
Ok, I'll try without sarcasm. ;)
The web server is built to process several web pages simultaneously using mutliple threads. The database is built to process several queries simultaneously using multiple sessions. If you use only one connection in your application, that will become the bottle neck of the application. Whatever you do, it will always boil down to the fact that only one thread at a time can access the database, and all the other threads have to wait their turn.
Open a connection for each page, and use that for the database operations in the page. When you close the connection it will be returned to the connection pool. Connections are only costly when you create them the first time. When there is a connection in the connection pool that can be reused, opening it is much faster.
Terry Jolly wrote:
No one has given a different view yet, accept to say I'm wrong and I'm leaving the conncection open, which is not true. So, I asked if opening 30+ connections made more sense than one connection if in both cases the connection would be opened the same amount of time (which no-one yas yet answered). I really would like to hear another point of view. I have not discounted anything anyone has said. Someone did say:.
my suggestion is having one class that just handles commands to
database.
your other 30+ classes would just prepare commands and pass them for
execution. So you will have central place for working with
SQLConnection object
Which I like and am (have been) diagraph/mapping out to see if this would work. Don't be offended about asking to clarity you position better. It doesn't mean I think your wrong.
"Göran Andersson" <guffa@xxxxxxxxx> wrote in message news:uJFn2b2dGHA.1272@xxxxxxxxxxxxxxxxxxxxxxxYes, you are probably right.
He got a lot of answers, but he didn't seem to listen to anyone who didn't already agree with him. Mark Rae even answered him using my own words, so there wasn't much I could add to that. I thought that I'd try a different angle, but I might have taken it a bit too far.
Anyway, if he don't want to listen, a different angle will probably not work anyway.
Ray Booysen wrote:Hi Göran
Sarcasm like this isn't neccessary. Someone asked a question to something that he/she obviously didn't know the correct answer for.
It doesn't help answering the question in this sort of vein.
Regards
Ray
Göran Andersson wrote:Using only one single database connection for a web application? Good one...
You could just as well neuter the web server by only allowing one single thread, as the other threads only will be waiting for the connection to get free.
What database are you using? If you are only going to use a single connection against it you should consider downgrading to something low-grade like MSDE or Access. Or why not anything even simpler like storing the data in text files?
Terry Jolly wrote: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 string in the web.config.
I created a class with a static database connection and the class opens and closes the database.
This seems to work so the question: Is there a better way to handle the database connection?
Thanks In Advance.
- Follow-Ups:
- Re: Making a database connection global
- From: Terry Jolly
- Re: Making a database connection global
- From: Mark Rae
- Re: Making a database connection global
- References:
- Making a database connection global
- From: Terry Jolly
- Re: Making a database connection global
- From: Göran Andersson
- Re: Making a database connection global
- From: Ray Booysen
- Re: Making a database connection global
- From: Göran Andersson
- Re: Making a database connection global
- From: Terry Jolly
- Making a database connection global
- Prev by Date: Re: Making a database connection global
- Next by Date: Re: Making a database connection global
- Previous by thread: Re: Making a database connection global
- Next by thread: Re: Making a database connection global
- Index(es):
Relevant Pages
|