[tds_menu_login inline="yes" guest_tdicon="td-icon-profile" logout_tdicon="td-icon-log-out" show_menu="yes" toggle_txt="Your Profile" menu_uh_padd="12px 20px" menu_ul_padd="12px 20px" menu_ulo_padd="12px 20px" menu_gc_padd="12px 20px" menu_gh_padd="15px 20px" menu_uh_color="var(--lc-primary)" menu_uh_border_color="var(--lc-lgrey-c1)" menu_bg="var(--lc-greyish)" menu_ul_link_color="var(--lc-black)" menu_ul_link_color_h="var(--lc-primary)" menu_ul_sep_color="var(--lc-lgrey-c1)" menu_uf_txt_color="var(--lc-black)" menu_uf_txt_color_h="var(--lc-primary)" menu_uf_icon_color="var(--lc-black)" menu_uf_icon_color_h="var(--lc-primary)" menu_uf_border_color="var(--lc-lgrey-c1)" f_uh_font_family="sans-serif_global" f_links_font_family="sans-serif_global" f_uf_font_family="sans-serif_global" f_uh_font_size="14" f_links_font_size="14" f_uf_font_size="14" f_uf_font_line_height="1.2" f_links_font_line_height="1.2" f_uh_font_line_height="1.2" f_uh_font_weight="500" f_links_font_weight="400" f_uf_font_weight="500" menu_ul_sep_space="0" menu_ul_space="10" f_gh_font_family="sans-serif_global" f_btn1_font_family="sans-serif_global" f_btn2_font_family="sans-serif_global" show_version="" toggle_txt_color="var(--lc-black)" toggle_txt_color_h="var(--lc-primary)" icon_color="var(--lc-black)" icon_color_h="var(--lc-primary)" f_toggle_font_family="sans-serif_global" f_toggle_font_transform="" f_toggle_font_size="eyJhbGwiOiIxNiIsInBvcnRyYWl0IjoiMTQifQ==" f_toggle_font_line_height="1.2" f_toggle_font_weight="600" menu_arrow_color="var(--lc-greyish)" menu_border_color="var(--lc-greyish)" menu_shadow_shadow_size="0" menu_shadow_shadow_offset_vertical="0" f_gh_font_size="14" f_btn1_font_size="14" f_btn2_font_size="14" f_btn2_font_line_height="1.2" f_btn1_font_line_height="1.2" f_gh_font_line_height="1.2" menu_gh_color="var(--lc-primary)" menu_gh_border_color="var(--lc-lgrey-c1)" menu_gc_btn1_bg_color="var(--lc-lgrey-c1)" menu_gc_btn1_bg_color_h="var(--lc-primary)" menu_gc_btn1_color="var(--lc-black)" menu_gc_btn1_color_h="var(--lc-white)" menu_gc_btn1_border_color="var(--lc-lgrey-c1)" menu_gc_btn1_border_color_h="var(--lc-primary)" menu_gc_btn2_color="var(--lc-black)" menu_gc_btn2_color_h="var(--lc-primary)" f_gh_font_weight="500" f_btn2_font_weight="500" f_btn1_font_weight="500" menu_gh_txt="Explore account options." icon_size="20" avatar_size="20" disable_dropdown="yes" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjAiLCJwYWRkaW5nLXJpZ2h0IjoiMjAiLCJib3JkZXItY29sb3IiOiJ2YXIoLS1sYy1kYXJrLWJsdWUpIiwiZGlzcGxheSI6IiJ9fQ=="]

Become a member

Get the latest updates and tutorials relating to Artificial Intelligence (AI).

― Advertisement ―

How to Write Engaging Blogs People Want to Read

Tips and tricks to write engaging blogs. From understanding your audience to SEO optimization, this guide covers it all.
HomeArchiveADO connection performance test

ADO connection performance test

Does one ADO methodology fit all situations? I have seen many developers use a variety of different methods in regards to creating ADO connections and recordsets in an attempt to optimize performance. These range from putting ADO connection objects in Application and Session variables and reusing the open connection for all of their pages to creating one ADO connection per page. And of course, everything else in between.

With this in mind, I’ve put together a little script to demonstrate why the following steps should always be taken with each ADO database action in the ASP page. At least this is what we’ve been led to believe…

1. Create the ADO objects needed.
2. Perform the database task (select, insert, update, delete, etc…) with stored procedures if available.
3. Close open database connections on all ADO objects.
4. Destroy all ADO objects.

Windows DNA teaches us that all objects should be created, used, and destroyed as soon as possible in order to free up resources on the server. With connection pooling via IIS, we allow IIS to manage the physical database connections for us after we release the connection and objects in our code. IIS can then simply hand the existing connection off to another user again without the normal overhead. As a side note, Microsoft Access does not take advantage of connection pooling. With a smaller number of visitors as sites using MS Access would have, this methodology still applies without a performance hit. We should try to avoid using connected ADO objects in Application and Session variables. Why? Because an connected ADO object (typically a recordset) is not threadsafe. All subsequent requests for the object are locked down to the single thread of execution it was instantiated on, effectively forcing IIS to make all requests WAIT until the object has been used and released by everybody in front of you, no mater how many other threads are available (125 by default).

I recommend adjusting the code sample and trying it with various database tasks. In this example, I’ve executed 300 database tasks in order to show a variance in performance for a larger load average. Keep in mind, IIS connection pooling is not turned on by default (is on by default in Win2k IIS5.0). You’ll have to adjust the registry setting in order to activate it. Set the following registry entry if it has not already been done:

Parameters StartConnectionPool = 1

As always, I try to test Microsoft theories before preaching them as gospel. What I’ve said so far pretty much matches common theory among engineers.

Let’s run a little test with the Northwind database to see if we are correct in all cases. Pay particular attention to the differences between stored procedures and string queries!

Run the test now…

Download the code…

A raised eyebrow eh? Of course, you’ll want to run the test several times and look for a constant pattern because ASP is not the “perfect” timer. I also put all of these in the same script. During testing, I didn’t notice any consistant difference when these were broken up into separate files. But, you may opt to conduct your own individual file test.

To summarize, we learned that reusing the same connection and objects can improve performance. However, this test assumes the database interaction is all closely tied together. In normal ASP pages, this isn’t always the case. If we are processing HTML or various routines in between database calls, we should seriously consider destroying the current connection and objects beforehand. Then, recreate the objects and connections as needed.

We don’t want to hold onto connections and objects any longer than necessary while processing non-database oriented tasks or run the risk of not explicitly closing connections and destroying our objects because of errors. This is just one more reason why we should try to modularize our ASP code and not interwine our HTML any more than absolutely necessary (not too mention the code is just easier to support…). I would love to hear your feedback on the test and ways to make it more accurate.

Robbe D. Morris


Please enter your comment!
Please enter your name here