473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Best way to call functions?

Dear all

I have written a very complex web app for intranet use. It allows
users to search a large database and then returns formatted results. I
am currently employing a method as below:

1. Create a global database connection
2. Open a recordset that searches the database
3. Loop through recordset calling the relevant function from an
include file to display results
4. Loop until EOF or PageSize reached.
5. Close and destroy recordset
6. Close and destroy connection
Formatting function on include does the following:
1. Create a recordset and open the record passed into the function as
a primary key ID.
2. Display each field in a formatted fashion.
3. Close and destroy recordset.

Is this efficent? There is a lot of creation and destruction of
recordset objects (a typical search result may yield up to 400
records) - each time a result is returned in fact. Additionally the
database is queried twice for the same result. Once for the search
recordset and then again for the formatting function. This has got to
be slow and inefficient unless Microsoft have some clever thing that I
don't understand similar to connection pooling (although I appreciate
that this is only for ODBC connections to a database and nothing to do
with recordsets!)

I am aware that I could do this all inline in the main page - but the
formatting is employed at several different locations in the database.
What's worse is that the formatting function may call other formatting
functions to retrieve formatted data in other tables that work in a
similar fashion.

Whilst this makes my code very easy to read and re-useable I am
concerned that I am paying a very big penalty. Is there any way around
this?

Options I considered:
- Recordsets declared globally - always available for use. (Although
this won't work in many cases as lots of the functions are recursive)
- plus this is messy!
- Passing open recordsets by reference in the "right place" (on the
correct record) to the function for it to manipulate. Is this
efficient?
- As above but passing by value? Is this just as slow?
- Putting it all inline - will improve performance - but at the cost
of reusable code

Please advise - I'm pulling my hair out! Any changes will take me
several days to do (there's a lot of this code!) so I want to make
sure I get it right!!

Thanks in advance
Jason.
Jul 19 '05 #1
2 1740
Hi Jason,
I read in a book and websites that is the best:
create objects and just after your use destroy them!
I believe that related to that I mentioned above, your application is fine.
About the rest, let the others say something.
bye,
--

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC
"Jason Gates" <ja*********@bepart.co.uk> escreveu na mensagem
news:8b**************************@posting.google.c om...
Dear all

I have written a very complex web app for intranet use. It allows
users to search a large database and then returns formatted results. I
am currently employing a method as below:

1. Create a global database connection
2. Open a recordset that searches the database
3. Loop through recordset calling the relevant function from an
include file to display results
4. Loop until EOF or PageSize reached.
5. Close and destroy recordset
6. Close and destroy connection
Formatting function on include does the following:
1. Create a recordset and open the record passed into the function as
a primary key ID.
2. Display each field in a formatted fashion.
3. Close and destroy recordset.

Is this efficent? There is a lot of creation and destruction of
recordset objects (a typical search result may yield up to 400
records) - each time a result is returned in fact. Additionally the
database is queried twice for the same result. Once for the search
recordset and then again for the formatting function. This has got to
be slow and inefficient unless Microsoft have some clever thing that I
don't understand similar to connection pooling (although I appreciate
that this is only for ODBC connections to a database and nothing to do
with recordsets!)

I am aware that I could do this all inline in the main page - but the
formatting is employed at several different locations in the database.
What's worse is that the formatting function may call other formatting
functions to retrieve formatted data in other tables that work in a
similar fashion.

Whilst this makes my code very easy to read and re-useable I am
concerned that I am paying a very big penalty. Is there any way around
this?

Options I considered:
- Recordsets declared globally - always available for use. (Although
this won't work in many cases as lots of the functions are recursive)
- plus this is messy!
- Passing open recordsets by reference in the "right place" (on the
correct record) to the function for it to manipulate. Is this
efficient?
- As above but passing by value? Is this just as slow?
- Putting it all inline - will improve performance - but at the cost
of reusable code

Please advise - I'm pulling my hair out! Any changes will take me
several days to do (there's a lot of this code!) so I want to make
sure I get it right!!

Thanks in advance
Jason.

Jul 19 '05 #2
Jason Gates wrote:
Dear all

I have written a very complex web app for intranet use. It allows
users to search a large database and then returns formatted results. I
am currently employing a method as below:

1. Create a global database connection
Ignore the following if you mean that you are opening a database connection
on each page.

************************************************** ********
Assuming you are storing this connection in Application, this is very bad.
ADO objects are not free-threaded, which means only one thread will be able
to use this connection object at a time. Connections should be opened late
and closed early in each page in which they are used.
http://www.aspfaq.com/2053

It is possible to use a batch file called makfre15.bat (located in
C:\Program Files\Common Files\System\ADO on my machine) to cause a registry
change to make the ADO objects free-threaded, allowing you to use them in
Application. However, if any applications on that machine are connecting to
Jet databases (Access), YOU MUST NOT DO THIS.
************************************************** ********

2. Open a recordset that searches the database
3. Loop through recordset calling the relevant function from an
include file to display results
4. Loop until EOF or PageSize reached.
Here are some alternatives that may improve your performance:
http://www.aspfaq.com/show.asp?id=2120
5. Close and destroy recordset
6. Close and destroy connection


Excellent.

You may wish to consider using GetRows arrays to avoid all the recordset
looping - looping through recordsets is incredibly slow compared to looping
through arrays. Better yet, if possible, make use of GetString. Take a look
at this:
http://www.aspfaq.com/show.asp?id=2467

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #3

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

Similar topics

6
by: Philip Warner | last post by:
I have a set of classes: C (base) C1 (inherits C) C2 (inherits C) ... Cn (inherits C) (the C1..Cn also have subclasses, but thats not really relevant to the question)
21
by: John Salerno | last post by:
If I want to make a list of four items, e.g. L = , and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
5
by: gw7rib | last post by:
I'm writing a program which has "notes" - these can appear on the screen as windows with text in. It is possible to create an "index note" - at present, this will contain a list of the titles (or...
2
by: David T. Ashley | last post by:
Hi, In my PHP code, I typically break my functions into groups (usually based on the data type they operate on), and then include the files, i.e.: require_once("string_functions.inc");...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
6
by: Jack | last post by:
I have a set of functions to wrap a library. For example, mylib_init() mylib_func() mylib_exit() or handle = mylib_init() mylib_func(handle)
1
by: dizzy | last post by:
My client application will have a set of varying business functions. These functions will be fullfiled via various 3rd party services (i.e. web services, http post/get, remote data access or socket...
7
by: Ashutosh Bhawasinka | last post by:
Hi, I have a C# .Net application which needs to use some feature which can be only developed in Visual C++ (its extended MAPI). The C# exe will be supplied to users without a setup. What kind...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.