Re: Making a database connection global
- From: "Mark Rae" <mark@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 May 2006 22:11:33 +0100
"Terry Jolly" <terry@xxxxxxxxx> wrote in message
news:4464f7d0$0$6150$39cecf19@xxxxxxxxxxxxxxxxxxxxx
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?
Yes - pretty much anything else would be better than what you're proposing.
If you did this you would quickly run into problems, as every user that
requests a page will be sharing the same connection. That means that only
one user at a time can request a page, or you will get an error message
because the connection is busy. Every page that uses the database needs its
own connection. This is one of the worst things you can do in ASP.NET - the
absolute LAST thing you should do is to keep a connection to your RDBMS open
for any longer than is necessary, let alone for the entire lifetime of your
web app.
Consider using a DAL (Data Access Layer) instead:
http://www.15seconds.com/issue/030317.htm
.
- Follow-Ups:
- Re: Making a database connection global
- From: Terry Jolly
- Re: Making a database connection global
- References:
- Making a database connection global
- From: Terry Jolly
- Making a database connection global
- Prev by Date: Re: Reading input field from innerhtml span
- Next by Date: Re: shopping cart binding to datagrid
- Previous by thread: Making a database connection global
- Next by thread: Re: Making a database connection global
- Index(es):
Relevant Pages
|