How to open secured database through ODBC without sending UID and PWD in connection string

How to open secured database through ODBC without sending UID and PWD in connection string

Post by Fulton Gree » Sat, 08 Mar 1997 04:00:00

Quote:> Is there a way to open an access database through ODBC without
> specifying the username and password in the connection string.
> If not it's very easy to find out the username and password through
> ODBC tracing.

Unless, of course, you turn the tracing off before the connection. This is
an example of how to do it with the 16-bit MFC database classes, by using a
subclass method override:

class CMoreSecureDatabase : public CDatabase
        virtual BOOL Open(LPCSTR lpszDSN,
                        BOOL bExclusive    = FALSE,
                        BOOL bReadonly     = FALSE,
                        LPCSTR lpszConnect = "ODBC;");


BOOL CMoreSecureDatabase::Open(LPCSTR lpszDSN,
                               BOOL bExclusive,
                               BOOL bReadonly,
                               LPCSTR lpszConnect)
   DWORD dwTraceOption = SQL_OPT_TRACE_OFF;

   // These two statements make sure that we can turn tracing off for the
   // Open method. Without them, the CDatabase code falters.
   // This is only guaranteed for 16-bit code. I have no idea if this
   // works for 32-bit code.
   m_bUpdatable = TRUE;

   // get the current tracing state
   SQLGetConnectOption(m_hdbc, SQL_OPT_TRACE, &dwTraceOption);

   // turn tracing off
   SQLSetConnectOption(m_hdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF);

   // now open securely
   BOOL bSuccess = FALSE;
      bSuccess = CDatabase::Open(lpszDSN,
   CATCH(CDBException, e)
      // error notification

   if (dwTraceOption != SQL_OPT_TRACE_OFF)
      SQLSetConnectOption(m_hdbc, SQL_OPT_TRACE, dwTraceOption);

   return bSuccess;



Quote:> I'm using Visual C++ to develop an app for 32 and 16 bit operating
> systems.  I intend to use DAO in the 32-bit version but I guess
> I'll have to use ODBC in the 16-bit version, or perhaps is there
> another way to open an access database in win3.x ?

I don't think there is. And beware of DELETE-related leaks in the
ODBC-to-Jet 16-bit driver path.

Hope this helps,
Fulton Green
Mantissa Corporation