Your database object must be initialized before you can use it to construct a recordset object.
If the lpszConnectString parameter in your OpenEx call does not contain enough information to make the connection, the ODBC driver opens a dialog box to obtain the necessary information from the user, provided you have not set CDatabase::noOdbcDialog or CDatabase::forceOdbcDialog in the dwOptions parameter. When you call OpenEx, your connection string, lpszConnectString, is stored privately in the CDatabase object and is available by calling the GetConnect member function.
If you wish, you can open your own dialog box before you call OpenEx to get information from the user, such as a password, and then add that information to the connection string you pass to OpenEx. Or you might want to save the connection string you pass so you can reuse it the next time your application calls OpenEx on a CDatabase object.
You can also use the connection string for multiple levels of login authorization (each for a different CDatabase object) or to convey other data source-specific information. For more information about connection strings, see Chapter 6 in the ODBC Programmer's Reference.
It is possible for a connection attempt to time out if, for example, the DBMS host is unavailable. If the connection attempt fails, OpenEx throws a CDBException.