Solved

ADO CreateInstance() Problem?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
Perl Awk Need Help 3 109
Hibernate methods 2 68
Bartender label printing - switch on and off graphics 3 14
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

15 Experts available now in Live!

Get 1:1 Help Now