Solved

ADO CreateInstance() Problem?

Posted on 2001-08-05
2
429 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
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

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

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 104
Replacement selected text 2 47
Define unique primary key 9 81
Making an alias 7 54
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now