Re: Function OpenConn
From: Aaron Bertrand [MVP] (aaron_at_TRASHaspfaq.com)
Date: 04/28/04
- Next message: Pete Casey: "Re: Tree query"
- Previous message: Jim Bowman: "Function OpenConn"
- In reply to: Jim Bowman: "Function OpenConn"
- Next in thread: Jim Bowman: "Re: Function OpenConn"
- Reply: Jim Bowman: "Re: Function OpenConn"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 27 Apr 2004 21:46:29 -0400
If the function is in an include file (or at the top of every page), you
could see a marginal increase in performance for those pages that don't use
a database connection at all, and therefore don't need to call the function.
(Of course, you could just as easily put the straight connection code into
its own include, and likewise decide whether to bother including the code at
all.)
However, I've found that abstracting this code into a function makes it very
tempting to wrap all database activity like this:
call openConn()
openConn.execute "INSERT ... "
call closeConn()
...other code...
call openConn()
openConn.execute "UPDATE ... "
call closeConn()
While logic will tell us that opening the connection and closing it as soon
as possible is the most efficient use of resources, this will rarely be the
case in reality. Opening and closing that connection multiple times in a
single page almost guarantees that your performance will suffer.
I'll be the first to admit that I use an #include file that unconditionally
opens a connection object at the top of the page, and another that closes
and destroys it at the bottom. That may seem wasteful, but keep in mind
that in 99% of the ASP applications I write, every page touches the
database. (For example, my navigation/menus are almost always driven by the
database.)
-- Aaron Bertrand SQL Server MVP http://www.aspfaq.com/ "Jim Bowman" <james@jbassoc.biz> wrote in message news:518801c42cbf$9539b7e0$a601280a@phx.gbl... > My Authorware training piece sends user scores to a > Microsoft Access database through an .asp page. In > opening the connection to the database, I use this code: > > function OpenConn() > > strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data > Source=" & Server.MapPath(".") & "\open_database.mdb;" > set OpenConn=Server.CreateObject > ("ADODB.Connection") > OpenConn.open strConn > > end Function > > In an IIS example, I see the three interior lines of > code, just as I have them, without the function code > ("function OpenConn" and "end Function") in the first and > last lines. Is there any value in using the function > code, e.g. does it improve reliability or performance? > > Thanks. > > Jim Bowman
- Next message: Pete Casey: "Re: Tree query"
- Previous message: Jim Bowman: "Function OpenConn"
- In reply to: Jim Bowman: "Function OpenConn"
- Next in thread: Jim Bowman: "Re: Function OpenConn"
- Reply: Jim Bowman: "Re: Function OpenConn"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|