Re: Making a database connection global



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@xxxxxxxxxxxxxxxxxxxxxxx
Yes, 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.
.



Relevant Pages

  • Re: ADO Connection Timeout
    ... so what happens when a connection failure forces one station to revert ... to a local database? ... Further, you *will* have contention issues, Jet does not support record ... to the central server, but you are willing to live with periods where it ...
    (microsoft.public.data.ado)
  • Re: Transfer Excel file from a Web Server to Local Server
    ... Have your web administrator create an System DSN name in the ODBC control ... panel on the web server then try it using the name they create. ... I was trying to create a new database connection through Form Properties. ...
    (microsoft.public.frontpage.programming)
  • Kerberos timout with IIS6, ASP.Net and SQLServer
    ... We have a traditional ASP.Net 1.1 web site accessing a SQL2000 database ... using delegation and a trusted connection. ... fully authenticated through Kerberos and Integrated ... The connection with the web server works fine, ...
    (microsoft.public.inetserver.iis.security)
  • Re: ADO Connection Timeout
    ... When the first test is run, the results are stored in the central database. ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)
  • Re: ADO Connection Timeout
    ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)

Quantcast