Re: ODBC error in inetinfoe.exe

From: Matt Neerincx [MS] (mattn_at_online.microsoft.com)
Date: 01/08/05


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
> 


Relevant Pages

  • Re: Files created when we run Embedded SQL
    ... That option ensures there is no ability for reuse of cursors in the job for that program. ... No matter what, when the service is actively processing, the lock is held; i.e. the conflict exists even w/out pseudo-closed, so the ability to both stop the service and prevent new requests is an effective requirement to avoid the conflict alluded to as origin for wanting to close the files.? ... It would be better to be able to provide the ability to ask the service to either close down the activation group or remove the lock ... QASQRESL is the /routine resolution/ file which is opened and tracked in static storage for the job; i.e. once open, it remains open for the performance benefit, for future function and procedure name resolution activity for SQL processing. ...
    (comp.sys.ibm.as400.misc)
  • Re: vpn - problems after connecting
    ... To configure H.323 filter ... Failed to create a RAS context for the IP address 192.168.0.111. ... API error text: The requested address is not valid in its ... Future SOCKS requests will be refused. ...
    (microsoft.public.windows.server.sbs)
  • Re: too much OOP ?
    ... You cannot say that without specifying what kind of requests are planned. ... That assumes that you can with SQL, and that there is no other components. ... that SQL database should never be used. ... downloading some free generic tool for applying logical ...
    (comp.object)
  • Re: ISAPI Filter as Proxy
    ... Filter/Extension DLL, where the Filter DLL matches the requests in question ... SF_NOTIFY_PREPROC_HEADERS, and if it matches, rewrite the URL to the ISAPI ... WinHttp call to the other server (DO NOT USE WININET ON A SERVER -- it is ...
    (microsoft.public.inetserver.iis)
  • Re: how do you handle multiple update request on the database?
    ... I made the assumption that the OP was using an RDBMS like SQL Server, ... requests that come in at the same time to the server. ... Any database will handle #2 fine. ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast