PRB: Cannot Use dbclose() or dbexit() in an OS/2 Exit Routine

Last reviewed: April 25, 1997
Article ID: Q76814

The information in this article applies to:
  • Microsoft SQL Server Programmer's Toolkit, version 4.2

SYMPTOMS

An OS/2 application will appear to hang if dbclose() or dbexit() is placed in the OS/2 exit routine.

CAUSE

When exiting an OS/2 program, all threads belonging to that application are first closed. Then the exit routine is run in the context of the main thread, the only remaining running thread.

When an OS/2 DB-Library (DB-Lib) program opens a connection to SQL Server using the dbopen() function, DB-Library creates a new thread for that application to manage the DBPROCESS connection. Thus, all DB-Library applications are multithreaded applications, and DB-Library handles all the multithreading automatically.

In addition, DB-Library uses semaphores to control access to the DBPROCESS connections. Many OS/2 DB-Library functions first wait on the DBPROCESS semaphore before proceeding, dbclose() and dbexit() among them. When this semaphore is cleared, the DBPROCESS is available and the function can proceed.

When exiting an OS/2 DB-Library application, all the DBPROCESS connection threads created by DB-Library are first closed by OS/2. Then the exit routine is run in the context of the main thread. If dbclose() or dbexit() is run in the exit routine, it first waits on the DBPROCESS semaphore. However, the DBPROCESS thread has already been closed by OS/2, thus the semaphore can never be cleared. As a result, dbclose() or dbexit() will wait forever on a semaphore that will never be cleared.

WORKAROUND

Because of the architecture of DB-Library, dbclose() or dbexit() cannot be called in an OS/2 exit routine registered with DosExitList().


Additional query words: dblib
Keywords : kbprg SSrvDB_Lib
Version : 4.2
Platform : OS/2


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.