Solved

ADO CreateInstance() Problem?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

10 Experts available now in Live!

Get 1:1 Help Now