?
Solved

DAO Database, Open .mdb file?

Posted on 2005-04-16
10
Medium Priority
?
514 Views
Last Modified: 2013-11-20
Hi..

I am using the following code to open an access database file (.mdb) but when i run the application and choose the databse file it say "Unrecognized database format...." , can anyone give a hand into this please?

here is the code:

BOOL CPatientDoc::OnNewDocument()
{
      if (!m_DataBase.IsOpen())
      {
            // First assume patient.mdb file is in current directory
            try
            {
                  m_DataBase.Open(_T("patient.mdb"));
            }
            catch (CDaoException* e)
            {
                  // Assume failure is becauase we couldn't find the file
                  e->Delete();
            }
      }
      if (!m_DataBase.IsOpen())
      {
            // Now pop-up file-open dlg to ask for location
            CFileDialog dlgFile(
                  TRUE,
                  _T(".mdb"),
                  NULL,
                  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
                  _T("Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*||"));
            if (dlgFile.DoModal() == IDCANCEL)
                  return FALSE;
            try
            {
                  m_DataBase.Open(dlgFile.GetFileName());
            }
            catch (CDaoException* e)
            {
                  // Tell them the reason it failed to open
                  AfxMessageBox(e->m_pErrorInfo->m_strDescription);
                  e->Delete();
                  return FALSE;
            }
      }
      if (!m_DataBase.IsOpen())
            return FALSE;
      m_pPatientSet = new CPatientSet(&m_DataBase);
      m_pPatientSet->Open();

      if (!CDocument::OnNewDocument())
            return FALSE;
      
      CConnectDlg dlg;
      if( dlg.DoModal() == IDOK )
      {
         if( dlg.m_SerCli == 0 )
         {
                  if( m_pMainSocket == NULL )
                  {
                        m_pMainSocket = new CMainSocket(this);
                        if (m_pMainSocket->Create(dlg.m_Port))
                        {
                              if (!m_pMainSocket->Listen())
                              {
                                    AfxMessageBox( "Verify Connection!." );
                                    return FALSE;
                              }
                        }
                  }
         }
         else if( dlg.m_SerCli == 1 )
         {
                  ConnectSocket( dlg.m_IPStr , dlg.m_Port );
         }
         m_SerCli = dlg.m_SerCli;
         m_IPStr = dlg.m_IPStr;
         m_Port = dlg.m_Port;
      }
      else
            return FALSE;

      if (!CDocument::OnNewDocument())
            return FALSE;

      return TRUE;
}
0
Comment
Question by:hlaith
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 672 total points
ID: 13800048
What version of MS Access is your database file?

You'll get that error if you have MS Access 2000 or higher and you don't have the latest version of MS Jet Engine.

You can either upgrade MS Jet Engine, or you can convert your MS Access DB file to a version prior to 2000 version.
0
 
LVL 7

Assisted Solution

by:jimwasson
jimwasson earned 664 total points
ID: 13800059
This sounds like the MFC Jet hack problem. You have to "force" MFC to use DAO 3.5 by placing the following line early in your program. A good place is at the beginning of InitInstance():

AfxGetModuleState()->m_dwVersion = 0x0601;

It is S hack to force MFC to use DAO3.6.  Ref MS KB article Q236991.
0
 
LVL 7

Expert Comment

by:jimwasson
ID: 13800060
force" MFC to use DAO 3.5

Sorry, I meant DAO 3.6, not 3.5.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:hlaith
ID: 13801349
Hi i have converted the mdb file to Access 97 format, but still gives me the same error ...

I also tried placing the code in initinstance(), but i got the following error:

 'm_dwVersion' : is not a member of 'AFX_MODULE_STATE'


Any suggestions?
0
 
LVL 30

Expert Comment

by:Axter
ID: 13801426
Are you sure you're opening the right file.

Try giving a full path when you open the file.
0
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 664 total points
ID: 13804531
This sounds like a static build (MFC statically linked).
The fiollowing from Jimwasson WILL work for a shared build.
AfxGetModuleState()->m_dwVersion = 0x0601;

For a static build you would have to recompile the MFC libraries to be able to use an Access 2000 or higher format database.  (Yeuch)

You have three options.
1) Access 2000, shared build - Project settings, general tab, Use MFC in shared dll.
2) Access 97, no need for the line AfxGetModuleState()->m_dwVersion = 0x0601;
3) Forget DAO, use ADO or some other technology

I'd use option 1 or 2 for an existing project.  For new projects look at ADO (DAO was more or less finished with Access 97)
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16298106
split between all experts
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question