Solved

ADO CreateInstance() Problem?

Posted on 2001-08-05
2
434 Views
Last Modified: 2013-11-20
I have a simple console app that I'm trying to use ado to connect to.
When I run my code:
spADOConn.CreateInstance( __uuidof(Connection));
spADOConn seems to always contain the value of
0x000...

Am I doing something wrong here?
My stdafx.h only contains the following:
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

Here is my code:

#include "stdafx.h"
#include <stdio.h>

#pragma warning(disable: 4146)
#import "C:/Program Files/Common Files/System/ADO/MSADO15.DLL" \
no_namespace rename("EOF","adoEOF")
#pragma warning(default: 4146)


int main(int argc, char* argv[])
{
     _ConnectionPtr spADOConn = NULL;

     try
     {
         

          spADOConn.CreateInstance( __uuidof(Connection));

          spADOConn->Mode = adModeReadWrite;
          if (SUCCEEDED(spADOConn->Open("Data Source=ADOClientDS",
               "","",adConnectUnspecified)))
          {
               spADOConn->Close();

               printf( "True" );
          }
          else
          {
               printf( "Err" );
          }
     }
     catch( ... )
     {

     }
     return 0;
}
0
Comment
Question by:borg48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 50 total points
ID: 6357114
Call CoInitialize right at the start of the main function. This will initilaize the COM libraries that you need to create the COM objects,
0
 

Author Comment

by:borg48
ID: 6357907
Thanks allot
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 104
windows 10 how make picture as desktop background 2 73
java ^ examples 8 75
c++  placing data into a form and an editbox 5 50
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

710 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