// TestODBCDoc.cpp : implementation of the CTestODBCDoc class // #include "stdafx.h" #include "TestODBC.h" #include "TestODBCDoc.h" #include ".\testodbcdoc.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CTestODBCDoc IMPLEMENT_DYNCREATE(CTestODBCDoc, CDocument) BEGIN_MESSAGE_MAP(CTestODBCDoc, CDocument) ON_COMMAND(ID_TOOLS_ODBCDEBUG, OnToolsOdbcdebug) END_MESSAGE_MAP() // CTestODBCDoc construction/destruction CTestODBCDoc::CTestODBCDoc() { // TODO: add one-time construction code here } CTestODBCDoc::~CTestODBCDoc() { } BOOL CTestODBCDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } // CTestODBCDoc serialization void CTestODBCDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } // CTestODBCDoc diagnostics #ifdef _DEBUG void CTestODBCDoc::AssertValid() const { CDocument::AssertValid(); } void CTestODBCDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG // CTestODBCDoc commands void CTestODBCDoc::OnToolsOdbcdebug() { try { CDatabase database; if (database.OpenEx(NULL, CDatabase::forceOdbcDialog)) { CString strMessage, strConnect = database.GetConnect(); strMessage.Format(_T("%s\n%d chars"), (LPCTSTR)strConnect, strConnect.GetLength()); AfxMessageBox(strMessage); database.Close(); if (database.OpenEx(strConnect, CDatabase::noOdbcDialog)) AfxMessageBox(_T("Database successfuly opened")); else AfxMessageBox(_T("Database could not be opened")); } } catch (CException* e) { e->ReportError(); e->Delete(); } }