Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ADO problem

ADO problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasecomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    unknown soldier
    wrote on last edited by
    #1

    I am writing a simple console application with MFC support in order to connect to Database using ADO. But having problems in the initial stages. The main program looks something like this:

    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    _ConnectionPtr m_pConnection;

              HRESULT hr;
    
    
    if(!AfxOleInit())
    {
    	printf("\\n COM initialization failed"); 
    }
    

    hr = m_pConnection.CreateInstance( __uuidof( Connection ) );

    if (SUCCEEDED(hr))
    	printf("\\n createInstance successful");
              
    
         else
         printf("CreateInstance unsuccessful");
    

    The problem is that CreateInstance is failing. Please tell me the problem if you find out. Oh yea, i added following lines in StdAfx.h:

    include #import "C:\program files\common files\system\ado\msado15.dll" \
    no_namespace \
    rename( "EOF", "adoEOF" )

    R 1 Reply Last reply
    0
    • U unknown soldier

      I am writing a simple console application with MFC support in order to connect to Database using ADO. But having problems in the initial stages. The main program looks something like this:

      int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
      {
      _ConnectionPtr m_pConnection;

                HRESULT hr;
      
      
      if(!AfxOleInit())
      {
      	printf("\\n COM initialization failed"); 
      }
      

      hr = m_pConnection.CreateInstance( __uuidof( Connection ) );

      if (SUCCEEDED(hr))
      	printf("\\n createInstance successful");
                
      
           else
           printf("CreateInstance unsuccessful");
      

      The problem is that CreateInstance is failing. Please tell me the problem if you find out. Oh yea, i added following lines in StdAfx.h:

      include #import "C:\program files\common files\system\ado\msado15.dll" \
      no_namespace \
      rename( "EOF", "adoEOF" )

      R Offline
      R Offline
      RChin
      wrote on last edited by
      #2

      You need to initialise the COM library by calling ::CoInitialize() eg: if( FAILED(::CoInitialize(NULL)) ) // Initialise COM { AfxMessageBox(IDS_ERROR_COM_INITIALISE, MB_OK | MB_ICONEXCLAMATION); return FALSE; } Chin

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups