Solved

Open database???

Posted on 1998-10-21
6
453 Views
Last Modified: 2013-11-20
Hi All,

I am doing a project using which need to build a database and then open it to input data. The database is in mdb format.I have made an execute file from the project and test
the program in another computer without installing Visual C++ 5.0/Microsoft Access.

But I found that the database cannot be opened or created.
What is the problem? How can I open/create a database in using another computer without installing VC/Access/VB...

Thanks!!!

Here is the source code to build the database in my program:

CDaoFieldInfo m_FI;
CDaoIndexInfo m_II;                  

      try
      {
            (*ppDatabase)->Create(lpszPathName, dbLangGeneral ,dbVersion30);
      }
      catch (CDaoException *e)
      {
            CString message = _T("Couldn't create database--Exception: ");                
            message += e->m_pErrorInfo->m_strDescription;                             
            AfxMessageBox(message);                                                                   
            e->Delete();
            delete *ppDatabase;
            *ppDatabase = NULL;
            
      }
      catch (CMemoryException *e)
      {
            AfxMessageBox(_T("Failed to create database--Memory exception thrown."));  
            e->Delete();
            delete *ppDatabase;
            *ppDatabase = NULL;
      }

      CString m_strTableName = "Users";
      CDaoTableDef **ppTableDef = &ProTableDef;
      *ppTableDef = new CDaoTableDef(ProDatabase);
      // so create the tabledef if possible
      
      TRY
      {                                                                                             
            (*ppTableDef)->Create(m_strTableName);                                                      
      }                                                                                             
      CATCH (CDaoException, e)
      {                                                                                             
            CString strMessage = _T("Couldn't create tabledef--Exception: ");                                
            strMessage += e->m_pErrorInfo->m_strDescription;                                             
            AfxMessageBox(strMessage);
            // delete the tabledef on failure                                                      
            if (*ppTableDef != NULL)                                                                  
            {                                                                                         
                  delete *ppTableDef;                                                                   
                  *ppTableDef = NULL;                                                                   
            }                                                                                         
      }                                                                                             
      AND_CATCH (CMemoryException, e)
      {
            AfxMessageBox(_T("Failed to create tabledef--Memory exception thrown."));                  
            if (*ppTableDef != NULL)                                                                  
            {                                                                                         
                  delete *ppTableDef;                                                                   
                  *ppTableDef = NULL;                                                                   
            }                                                                                         
      }
      END_CATCH          
      
      // property of the fields
      m_FI.m_lSize=20;
      m_FI.m_lAttributes |= dbVariableField;
      m_FI.m_nOrdinalPosition = 0;
      m_FI.m_strName = _T("Telephone Number");
      m_FI.m_nType = dbText;      
      m_FI.m_strDefaultValue = _T("");
      m_FI.m_bRequired = FALSE;
      m_FI.m_bAllowZeroLength = TRUE;
      m_FI.m_strValidationRule = _T("");
      m_FI.m_strValidationText = _T("");
      
      //create the fields
      ProTableDef->CreateField(m_FI);
      ProTableDef->Append();
      m_FI.m_strName = _T("First Name");
      ProTableDef->CreateField(m_FI);
      m_FI.m_lSize=30;
      m_FI.m_strName = _T("Last Name");
      ProTableDef->CreateField(m_FI);
      m_FI.m_strName = _T("E-mail");
      ProTableDef->CreateField(m_FI);
      m_FI.m_strName = _T("Company");
      ProTableDef->CreateField(m_FI);

      m_II.m_strName = _T("Telephone Number");
      m_II.m_bPrimary = FALSE;
      m_II.m_bIgnoreNulls = FALSE;
      m_II.m_bRequired = FALSE;
      m_II.m_bUnique = FALSE;

      if (m_II.m_pFieldInfos != NULL)
      {
            delete [] m_II.m_pFieldInfos;
            m_II.m_pFieldInfos = NULL;
            m_II.m_nFields = 0;
      }

      CDaoIndexFieldInfo **ppFields=&(m_II.m_pFieldInfos);      
      (*ppFields)=new CDaoIndexFieldInfo[1];

      //short *pnFields;
      //*pnFields=0;
      (*ppFields)[0].m_strName="Telephone Number";
      (*ppFields)[0].m_bDescending= FALSE;
      
      m_II.m_nFields=1;
      
//      m_II.m_pFieldInfos=*ppFields;
      // try create index
      
      TRY                                                                   
      {                                                                     
            ProTableDef->CreateIndex(m_II);                            
      }                                                                     
      CATCH (CDaoException, e)                                              
      {                                                                     
                  CString message = _T("Couldn't create Index--Exception: ");           
            message += e->m_pErrorInfo->m_strDescription;
            
            AfxMessageBox(message);                                                      
      }                                                                     
      AND_CATCH (CMemoryException, e)
      {
            AfxMessageBox(_T("Failed to create Index--Memory exception thrown."));                                             
      }
      END_CATCH                                                             

      
      if (ProDatabase != NULL)
      {
            if ((ProDatabase)->IsOpen())
                  (ProDatabase)->Close();
            // closing doesn't delete the object
            delete *ppDatabase;
            *ppDatabase=NULL;
            delete *ppTableDef;
            *ppTableDef=NULL;
            if ((*ppFields) != NULL)
            {
                  delete [] (*ppFields);
                  *ppFields = NULL;
            }      
      }
      
      }

0
Comment
Question by:kkuu
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
Comment Utility
It's probably not your code but the massive list of DLLs that you must include when distributing your product.  If this will be a redistributable product that you are going to develop an installation program for, get an advanced install such as InstallShield that came with Visual C or InstallShield express.  When using these products, you can select both a DAO and a ODBC distribition list.  Then all required DLLs will be included for you.  

Otherwise, throw in your MSCD that you got with Visual C and look for DAO and Redistributable to give you a complete list depending on the version of visual C that you are currently using.

Good luck, the list is about 20 files long!

Phillip
0
 

Author Comment

by:kkuu
Comment Utility
Dear Sir,

I don't know how to use the InstallShield. I tried to make a setup.exe, but it is not
success.
Can you list the procdeure need to build a setup.exe file?

Thanks!!!
0
 

Author Comment

by:kkuu
Comment Utility
Dear Sir,

Can you list the dll files required in order to open/create a database?

I don't have enough time to learn how to use the InstallShield now...Thanks!!!

Bye
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:psdavis
Comment Utility
HOWTO: Redistributing DAO with Your Visual C++ 5.0 Application
Last reviewed: September 30, 1997
Article ID: Q167523  
The information in this article applies to:
Microsoft Visual C++, 32-bit Editions, version 5.0


SUMMARY
There are 2 approaches to redistributing DAO 3.5 with your Visual C++ 5.0 application:

You can redistribute the DAO Setup located in the VC\REDIST\DAO directory.

-or-
You can follow the steps in the Daosetup.rtf installed with the DAO SDK.

Note that the information in the "Installing DAO on Another Machine" topic for the DAO SDK is incorrect and the information should be ignored.


MORE INFORMATION


Redistributing the DAO Setup
On the Visual C++ 5.0 CD, under \DEVSTUDIO\VC\REDIST\DAO\DISK1\, there is a DAO Setup program that can be redistributed. This setup program prompts the user for information about which components to install. You can run the setup program with a '-s' option that silently runs the DAO Setup without putting information on the screen.

Here are a few important notes:

If you run the program with the -s option, all of the DAO components will be installed (DAO core components, ODBC Direct, and ISAMs).
If ODBCDirect is selected or you chose the '-s' option, you must have ODBC 3.0 currently installed on the system.
To register DAO and use DAO, you must have Oleaut32.dll version 2.20.4049 or later as well as Stdole2.tlb installed into your System directory. If you try to run the setup program with the "-s" option and you do not have version 2.20.4049 or later, the setup program fails. To get these newer versions of the files, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q164529

   TITLE     : FILE: Updated Automation System Files

 

0
 

Author Comment

by:kkuu
Comment Utility
Dear Sir,

If I use the InstallShield from Visual C++, will the setup program automatically
setup the DAO properly?

I ask this because I know the file dao350.dll and da02535.tlb must be copied
into the directory "Program Files\Common Files....."

If the DAO can be setup properly by this method, how can I build the setup.exe file?

In using the InstallShield, I have only linked my project's exe file...then choose many
setup options. Any file need to be insert into the workspace anymore. Until
now I cannot build a setup.exe file successfully. Or do I need to write any code?

Thanks!!!

0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
> If I use the InstallShield from Visual C++, will the setup program automatically setup the DAO properly?

Yes, although I haven't personally had much experience with that version.  We went out and bought InstallShield Express instead to do it within minutes.  Most people use InstallShield so someone can help you.

Take a look at this Knowledge based article: Q167523 at the Microsoft web site or on your Visual C CD to get some more detailed information.  They're about five pages worth out there.

If you have your own setup file, then you need to include the DAO setup program with your file and run it once your setup.exe is finished.  Use the -s option for silent mode.  You must also have the ODBC installation as well.  Real pain, we're gonna go to ADO.

Good luck

Phillip

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now