asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

ODBC 3.0 Connection Pooling
By Wayne Berry
Rating: 3.0 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article


    ODBC 3.0 is a simple API which meets the requirements for a faster ISAPI Server Extension. It supports:

    • Multiple Threads to SQL Server
    • Handles Connection Caching
    • Is a low level API
    , In this issue we show how to use ODBC 3.0 connection caching to speed up ISAPI server extensions that connect to databases. , ODBC 3.0 is a simple API which meets the requirements for a faster ISAPI Server Extension. It supports:
    • Multiple Threads to SQL Server
    • Handles Connection Caching
    • Is a low level API
    , In this issue we show how to use ODBC 3.0 connection caching to speed up ISAPI server extensions that connect to databases.

    This Issue

    ODBC 3.0 is a simple API which meets the requirements for a faster ISAPI Server Extension. It supports:

    • Multiple Threads to SQL Server
    • Handles Connection Caching
    • Is a low level API
    , In this issue we show how to use ODBC 3.0 connection caching to speed up ISAPI server extensions that connect to databases. , ODBC 3.0 is a simple API which meets the requirements for a faster ISAPI Server Extension. It supports:
    • Multiple Threads to SQL Server
    • Handles Connection Caching
    • Is a low level API
    , In this issue we show how to use ODBC 3.0 connection caching to speed up ISAPI server extensions that connect to databases.

    Connection Pooling

    When connecting to a database from within an ISAPI server extension you must be fast. One way to do that is to pool connections to the database. Making a connection is expensive, usually making the connection takes longer then querying the data. For this reason if you can pool the connections you can save an enormous amount of time. Currently ODBC 3.0 is the only database API that caches connections.

    Besides connection pooling ISAPI server extension have some other requirements that need to be considered when choosing a database API.

    Why ODBC 3.0?

    When connecting to database you have many APIs to choose from including: ODBC, OLEDB, DAO, and ADO. We choose ODBC 3.0 because it handles connection caching and is a low level API.

    Example Code

    We have provided some example code of an ISAPI Server Extension that is thread safe and handles connection caching with ODBC 3.0

    Thread Safe

    All ISAPI server extensions must be thread safe. This includes the code that is specific to an the ISAPI server extension and all the APIs the ISAPI server extensions that the thread calls. It is important when choosing a database API that the API is thread safe. Currently ODBC, OLEDB, and ADO are thread safe. DAO is not thread safe, and should not be used in ISAPI server extensions.

    Why use ODBC 3.0?

    ODBC 3.0 supports Connection Caching, is thread safe, and is a low level API.

    Why not use OLEDB?

    OLEDB has more functionality then ODBC, is mufti-threaded, but does not support connection caching.

    Why not use ADO?

    ADO is easier to write then either OLEDB or ODBC, but ADO adds an extra layer that slows down the connection.

    Why not use DAO?

    DAO is the worst of the bunch, not only is it not thread safe, it does not support connection caching and is several layers above ODBC.

    Why Not Use OLEDB?

    There are three major reasons that we are not using OLEDB for this example.

    • OLEDB does not support connection caching.
    • OLEDB is slower then ODBC.
    • OLEDB requires more code.
    Each one of these is gone into detail below.

    Connection Caching

    One of the major reasons to avoid OLEDB when writing ISAPI server extensions is that it doesn't use connection caching. Since this Issue is all about connection caching in ISAPI server extensions we have chosen not to demonstrate OLEDB.

    OLEDB is slower then ODBC

    The current OLEDB provider from Mircosoft is a OLEDB layer to ODBC 3.0. Since it is a layer the OLEDB provider is slower then ODBC. So any call to Mircosoft OLEDB goes through ODBC 3.0. This means that if you can make an ODBC call directly then your call has the potenial to be faster.

    This is only true however when for the Mircosoft OLEDB provider. Other OLEDB providers could bypass ODBC. Currently however, there is only one OLEDB provider.

    More Code

    OLEDB was designed to accessing relational databases and non-relational databases. OLEDB proveds extra APIs that allow delvelopers to access non-relational databases. However this has an adverse effect on developers that want to access relational databases. It means that the an OLEDB developer writing to a realtional database will have to write more code then if he/she wrote staight to ODBC. More code might means more bugs.

    Requirements

    The code needs to be compiled with Microsoft Visual Developers Studio version 4.2 or better. Also, ODBC 3.0 needs to be installed on the machine that the code is compiled on and the machine that the code is to be run on.

    The Code

    Here is a code sample of an ISAPI Server Extension written using ODBC 3.0. This is fully commented skeleton code that you can take and use in your own ISAPI Server Extensions. You will need WinZip to extract the zip file since most of the file names are longer then 8.3.

    http://15seconds.com/files/121096.zip 8K.

    Code Notes

    A few notes about how the code operates and why.

    The ODBC Environment

    The ODBC Environment is allocated and set in the constructor of the ISAPI Server Extension. This guarantees two things. First of all it is only run once. Secondly, the constructor is thread safe, because it is only called once.

    The ODBC Environment is a member variable and is used by all threads entering the web space by the way of CallFunction. Since a single environment can handle multiple connections, this is not a problem. In fact having one constantly allocated environment aids the connection caching process.

    Notice that a flag (m_bBadConnection) is set if the code fails to make a connection successfully. This flag is checked in the method CallFunction(). A connection should not be allocated if the flag is TRUE.

    Parse Maps

    Notice that parse maps have been removed. By overriding CallFunction() we can handle all request in CallFunction(). This eliminates the need for Parse Maps.

    TODO

    The only code that needs to be added is the code that converts the skeleton code to code that performs a specific task. Look for the //TODO comment in the CallFunction() method.

    If you are not versed in the new ODBC 3.0 APIs you can still use the old ODBC 2.0 APIs with the hstmt variable. Connection Caching will not be effected if you use the skeleton code provided.

    ODBC Configuration

    You will need to set the DSN, User name and Password at the top of the ODBCExample.h file so that they match the ODBC Datasource that the ISAPI Server Extension queries.

    ODBC 3.0 Location

    ODBC 3.0 can be gotten free of charge from Microsoft on their web site.
    http://www.microsoft.com/ODBC/download/default.htm

    ODBC 3.0 Installation Tricks

    When Installing ODBC 3.0 keep these things in mind:

    • Since SQL Server uses ODBC you will need to stop SQL Server, SQL Server Executive and the Internet Information Server before installing ODBC 3.0
    • If you are using Microsoft Developer Studio then you will need to copy the ODBC libraries from

      c:\odbcsdk\lib32
      to
      c:\msdev\lib

      You will also need to copy the header files from:

      c:\odbcsdk\include
      to
      c:\msdev\include

      This will allow you to compile ODBC 3.0 with Microsoft Developers Studio.

    ODBC 3.0 and ODBC 2.0

    Installing ODBC 3.0 will not effect any ODBC 2.0 code. You will NOT need to recompile. Nor will you have to re-implement any of your data sources.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    Proposion N2N
    Proposion N2N connects Microsoft .NET applications to Lotus Notes and Lotus Domino databases. This ADO.NET managed data provider allows you to perform blindingly fast queries and updates of Notes data from ASP.NET pages, .NET web services, Windows, or Mobile applications. An innovative SQL-like query language leverages the unique features of Notes and makes collaborative software accessible to relational database programmers.
    [Top]
    Other Articles
    Sep 15, 2005 - Building an Image Keyword System
    Unlike text-based file formats image files aren't made up of words, which makes searching for an image file by keyword difficult. Instead of being able to simply open the file to see what it contains, we're stuck looking at the text around it and other metadata to determine the image's meaning. In this article, Ziran Sun shows you how to build a simple database-based image keyword system that allows you to associate keywords with images and use these keywords to make finding images easier.
    [Read This Article]  [Top]
    Apr 7, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 2
    In the second part of of his article on using MySQL with ASP.NET, Ziran Sun covers how to add a new MySQL user to the database server, assign the user the appropriate permissions, connect to the database, and build a simple ASP.NET page to perform a query.
    [Read This Article]  [Top]
    Feb 10, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 1
    Back in the days of classic ASP, if you were building a database-driven web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server (or some other enterprise-ready database) or invest a lot of time finding a way to deal with the performance and scalability limitations of Microsoft Access. Luckily these days there's another viable alternative: MySQL.
    [Read This Article]  [Top]
    Jan 27, 2005 - Moving a Database from SQL Server 7.0 to SQL Server 2000
    Moving or copying a SQL Server database from one machine to another requires a lot of preparation in order to ensure a smooth transfer. In this article, Dina Fleet Berry examines the different methods and highlights the different issues associated with each of them.
    [Read This Article]  [Top]
    Jan 6, 2005 - Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer
    There are many times when using SQL Server 2000 Query Analyzer to debug SQL statements is a better choice than debugging in Visual Studio .NET. In this article, Dina Fleet Berry explains why and walks you through the debugging process step-by step.
    [Read This Article]  [Top]
    Nov 24, 2004 - Persisting .NET Objects to SQL Server Using SQLXML and Serialization
    As a follow up to his article on retrieving objects from SQL Server using SQLXML and serialization, Gianluca Nuzzo discusses saving objects back to SQL Server using a schema definition file and updategrams.
    [Read This Article]  [Top]
    Sep 14, 2004 - Transaction Processing in ADO.NET 2.0
    One area that stands out when comparing ADO.NET 1.x to ADO.NET 2.0 is transaction processing. Bill Ryan shows just how easy transaction processing has become with the TransactionScope object in ADO.NET 2.0.
    [Read This Article]  [Top]
    Sep 8, 2004 - Custom Object Data Binding with .NET
    Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
    [Read This Article]  [Top]
    Sep 2, 2004 - Queue MSMQ Messages from SQL Server
    Learn how to create a console application to queue a message in Microsoft Message Queuing (MSMQ) and then use an extended stored procedure to call the console application from a SQL Server trigger.
    [Read This Article]  [Top]
    Aug 30, 2004 - Tuning Up ADO.NET Connection Pooling in ASP.NET Applications
    Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. This article shows how to monitor the connection pool, diagnose a potential problem, and apply the appropriate fix.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers