PRB: Calling CDatabase::Open in a USRDLL Causes CDBException (125794)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
This article was previously published under Q125794 SYMPTOMS
Calling the CDatabase::Open function in a USRDLL and using a parameter
list of (NULL, FALSE, FALSE, "ODBC;") may generate a CDBException with
it's m_strError member set to a value of "Dialog failed."
CAUSE
When the CDatabase::Open function is called with a value of NULL for the
first parameter and the default values for the remaining parameters, an SQL
Data Source dialog is displayed to the user allowing them to choose the
data source they want to open.
When this is done in the context of a USRDLL, the CDBException is generated
because CDatabase::Open() attempts to specify the main or active window of
the CWinApp or CWinThread object as the parent of the SQL Data Source
dialog. In a USRDLL, the main or active window of the CWinApp or CWinThread
object is typically NULL.
RESOLUTION
Avoid the problem by using the main window of the calling application as
the parent of the SQL Data Source dialog. The sample code listed below
illustrates one way to implement this solution. The sample DLL exports one
function, OpenDatabase(), which displays a dialog with a list of data
sources. The OpenDatabase() function accepts a single parameter of type
HWND, which is then used as the handle to the parent window of the SQL Data
Source dialog.
STATUS
This behavior was by design, however it was modified in Visual C++ version
2.2. to eliminate the problem.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbcode kbprb KB125794 |
---|
|