0

I'm a bit clueless at the moment what the problem is with this code. It trows a exception of type CDBException when trying to connect with the given ODBC Connect String and never comes back from .OpenEx - the lower message boxes never display.

There is a message from the ODBC Driver that states that the DSN isnt specified and that no default driver is found.

The Message Box that shows the connect string gives a good looking string - as it should, coming from a working connection

ODBC;DSN=DBTEST;Trusted_Connection=Yes;APP=XXX;WSID=NEUROMANCER;DATABASE=master;

Same problem when using SA/Password for the connection

ODBC;DSN=DBTEST_PW;UID=SA;PWD=password;APP=XXX;WSID=NEUROMANCER;DATABASE=master;

After reading other posts I added "DRIVER=" to the beginning and "SERVER=localhost;" to the end but that changed nothing. Resulting tested connection strings where

DRIVER=ODBC;DSN=DBTEST;Trusted_Connection=Yes;APP=XXX;WSID=NEUROMANCER;DATABASE=master;
DRIVER=ODBC;DSN=DBTEST;Trusted_Connection=Yes;APP=XXX;WSID=NEUROMANCER;DATABASE=master;SERVER=localhost

DRIVER=ODBC;DSN=DBTEST_PW;UID=SA;PWD=password;APP=XXX;WSID=NEUROMANCER;DATABASE=master;
DRIVER=ODBC;DSN=DBTEST_PW;UID=SA;PWD=password;APP=XXX;WSID=NEUROMANCER;DATABASE=master;SERVER=localhost

I also made sure to use the 32bit ODBC Admin tool to generate the system DSNs for the 32bit application.

If I replace "CDatabase::NoOdbcDialog" with "0" it opens the ODBC-Dialog again as if informations necessary to open the connection are missing.

db.OpenEx(NULL, CDatabase::forceOdbcDialog);
CString cstmp;
if (db.IsOpen()) {
    cstmp = db.GetConnect();
    db.Close();
}
MessageBox(cstmp, _T(""), MB_OK);
if (db.OpenEx(cstmp, CDatabase::noOdbcDialog )) { //Exception here CDBException at 0x004FDD9
    MessageBox(_T("Connection success!"), _T("Connection"), MB_OK);
    db.Close();
}
else {
    MessageBox(_T("Connection failed!"), _T("Connection"), MB_OK);
}

Can anyone tell me where my problem is?

Idenwen
  • 13
  • 4
  • You describe standard C++ exception handling rules (and seem to be confused by them). Regardless, a `CDBException` comes with an error message. Please post that error message, verbatim, and unabridged. – IInspectable Dec 27 '19 at 16:07
  • Not confused by the exception handling. Confused that there is a exception at all. Since all data comes from a working connection. The only GUI error message is "Data Source Name Not Found and No Default Driver Specified". In VS there are the following relevant lines in the debug output: CDBException at adress 0x007FDFD4 followed by Microsoft C++-Exception: [rethrow] at adress 0x00000000 followed by d:\agent\_work\3\s\src\vctools\VC7Libs\Ship\ATLMFC\Src\MFC\wincore.cpp(274) : AppMsg - Warning: Uncaught exception in WindowProc (returning 0). – Idenwen Dec 29 '19 at 01:45

0 Answers0