Re: ODBC error in inetinfoe.exe
From: Matt Neerincx [MS] (mattn_at_online.microsoft.com)
Date: 01/08/05
- Next message: Matt Neerincx [MS]: "Re: Mismatch Version ODBC"
- Previous message: Matt Neerincx [MS]: "Re: any need for %windir%\odbc.ini file in XP?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 7 Jan 2005 19:49:14 -0800
The code looks fine. The key thing with ODBC handles to remember:
1. Make absolutely sure you don't double free them, this can cause a crash.
2. There are mulitple APIs that can free the handles so try to be consistent
in your code.
For example SQLFreeStmt(hstmt,SQL_DROP) is equivalent to
SQLFreeHandle(SQL_HANDLE_STMT, hstmt).
3. As a good coding practice, close handles in reverse order of allocation,
as in your example.
4. Note that calling SQLDisconnect on an HDBC will automatically free all
active HSTMT handles associated with the HDBC, so following 3 is a good
idea. For example, this can cause a crash, many programmers are not aware
of this:
SQLAllocStmt(hdbc, &hstmt);
...
SQLDisconnect(hdbc);
...
SQLFreeStmt(hstmt, SQL_DROP); <- Crash here, hstmt is already freed!
As far as additional good programming practice in ISAPI/threading
environment, I recommend the following:
1. Try to keep activities short lived and local to a method call. Clean
everything up before you leave the method call.
2. Avoid any and all global HDBC and HSTMT handles. A global HENV is
acceptable and is probably preferrable for performance reasons, but be very
careful when initializing this that you only do it one time.
3. Use ODBC pooling to improve performance given 1 and 2.
4. Insure you set your timeouts appropriately so you don't hang the ISAPI
filter, in other words don't use an infinite timeout, use short but adequate
timeouts (query and connection timeouts).
5. Allow external users to configure the timeouts using registry key or ini
file, etc.. do not hard code them into the application. You will evenutally
run into the user who has the old tired SQL Server that is slow to respond
and may need to bump up the timeouts.
6. Be careful with userid and password strings, try to avoid them if
possible and use integrated login, integrated logins are usually easier to
manage from a overall security perspective.
Matt
-- This posting is provided "AS IS", with no warranties, and confers no rights. Please do not send email directly to this alias. This alias is for newsgroup purposes only. "Steve" <Steve@discussions.microsoft.com> wrote in message news:98E9F15B-10CF-4049-8440-498CA7BBA17F@microsoft.com... >I am accessing an SQL database inside an ISAPI filter. The application is > running on XP. The problem occurs with both SP1 and SP2. This is the first > ISAPI application I developed so maybe I'm doing something I'm not > supposed > to do. > > The filter DLL was developed with VC++.net. I am intercepting certain > requests that involve getting data from an SQL database and handling the > request directly from the filter. I am opening and closing the connection > to > process each request so as not to leave it intentionally open. At some > time > after the request is processed and sent to the requesting Web browser I > get > an error message: > > szAppName:inetinfo.exe szAppVer:5.1.2600.2180 szModName:odbc32.dll > szModVer:3.525.1117.0 offset:00002d6e > > The timeout for when the message occurs is exactly the timeout set in IIS > for inactive applications. While the connection is actively making > database > requests no errors occur. The requests are always successful as well as > future requests even when the error is not acknowledged. > > I am closeing the SQL connection in the following order: > > SQLCloseCursor(hstmt); > SQLFreeHandle(SQL_HANDLE_STMT, hstmt); > SQLDisconnect(hdbc); > SQLFreeHandle(SQL_HANDLE_DBC, hdbc); > SQLFreeHandle(SQL_HANDLE_ENV, henv); > > Is my close sequence wrong? Is the SQL interface I am using not > recommended > in an ISAPI filter? I have used the same code in MFC applications and > everything works fine without errors. > > Thanks for any help >
- Next message: Matt Neerincx [MS]: "Re: Mismatch Version ODBC"
- Previous message: Matt Neerincx [MS]: "Re: any need for %windir%\odbc.ini file in XP?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|