ADO Project 
Author Message
 ADO Project

Can someone enlighten me as to what I am doing wrong with this code? I'm
attempting create a simple executable using ADO 2.5. At this point the code
doesn't do anything other than declare a connection and open it. I can tell
VC6 resolves the import correctly because I can see all of the methods and
properties pop up while typing the code. Unfortunately it throws an error
about an undefined reference to _ConnectionPtr when I compile the code.

#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

WinMain()
{
    _ConnectionPtr pConnection = NULL;
    hResult = pConnection.CreateInstance("ADODB.Connection");
    pConnection->Open("Provider=SQLOLEDB;Data Source=testsrv;Initial
Catalog=Northwind;User ID=sa;Password=;", "", "", NULL);
    pConnection->Close();

Quote:
}



Tue, 04 Mar 2003 03:00:00 GMT  
 ADO Project
If this is the xact code snippet, it looks like you forgot to initialize the
COM object with CoInitialize(NULL); and at the end of WinMain() you should use
CoUninitialize();.
WinMain() {
    CoInitialize(NULL);

    ... All the stuff you want to do...

    ::CoUninitialize();

Quote:
}

I'm not expert, but what I gather from the documentation is the COM object must
be initialized before any calls to the Library functions.  If you are going to
be doing a lot of work with ADO and you don't have the July MSDN, I would
suggest picking it up.  It's very thorough.
Quote:

> Can someone enlighten me as to what I am doing wrong with this code? I'm
> attempting create a simple executable using ADO 2.5. At this point the code
> doesn't do anything other than declare a connection and open it. I can tell
> VC6 resolves the import correctly because I can see all of the methods and
> properties pop up while typing the code. Unfortunately it throws an error
> about an undefined reference to _ConnectionPtr when I compile the code.

> #import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

> WinMain()
> {
>     _ConnectionPtr pConnection = NULL;
>     hResult = pConnection.CreateInstance("ADODB.Connection");
>     pConnection->Open("Provider=SQLOLEDB;Data Source=testsrv;Initial
> Catalog=Northwind;User ID=sa;Password=;", "", "", NULL);
>     pConnection->Close();
> }



Thu, 06 Mar 2003 03:00:00 GMT  
 ADO Project
No, this isn't the exact code but I thought it would be enough to illustrate
the problem. It seems that VC6 can't find the declarations for
_ConnectionPtr (or any of the other ADO objects)... even though the IDE
editor knows these objects exist and shows tooltips with the correct methods
and parameters. I have the April 2000 MSDN installed so I'll pick up the
July edition to see if it has any other information.

Quote:

> If this is the xact code snippet, it looks like you forgot to initialize
the
> COM object with CoInitialize(NULL); and at the end of WinMain() you should
use
> CoUninitialize();.
> WinMain() {
>     CoInitialize(NULL);

>     ... All the stuff you want to do...

>     ::CoUninitialize();
> }

> I'm not expert, but what I gather from the documentation is the COM object
must
> be initialized before any calls to the Library functions.  If you are
going to
> be doing a lot of work with ADO and you don't have the July MSDN, I would
> suggest picking it up.  It's very thorough.


> > Can someone enlighten me as to what I am doing wrong with this code? I'm
> > attempting create a simple executable using ADO 2.5. At this point the
code
> > doesn't do anything other than declare a connection and open it. I can
tell
> > VC6 resolves the import correctly because I can see all of the methods
and
> > properties pop up while typing the code. Unfortunately it throws an
error
> > about an undefined reference to _ConnectionPtr when I compile the code.

> > #import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

> > WinMain()
> > {
> >     _ConnectionPtr pConnection = NULL;
> >     hResult = pConnection.CreateInstance("ADODB.Connection");
> >     pConnection->Open("Provider=SQLOLEDB;Data Source=testsrv;Initial
> > Catalog=Northwind;User ID=sa;Password=;", "", "", NULL);
> >     pConnection->Close();
> > }



Thu, 06 Mar 2003 03:00:00 GMT  
 ADO Project
I created a new simple Win32 console application project, stuck your
code (see below, it's slightly modified to use main and declaring the
HRESULT) and it compiled and linked fine.

Of course, it won't run because it doesn't include ::CoInitialize and my
server uses another name, but I'd say your problem lies in some other
part of your code.

/Martin

// simpleado.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

int main(int argc, char* argv[])
{

    _ConnectionPtr pConnection = NULL;
    HRESULT hResult = pConnection.CreateInstance("ADODB.Connection");
    pConnection->Open("Provider=SQLOLEDB;Data Source=testsrv;Initial
Catalog=Northwind;User ID=sa;Password=;", "", "", NULL);
    pConnection->Close();
        return 0;

Quote:
}

--------------------Configuration: simpleado - Win32
Debug--------------------
Compiling...
simpleado.cpp
Linking...

simpleado.exe - 0 error(s), 0 warning(s)

Quote:
-----Original Message-----

Posted At: Sunday, September 17, 2000 4:41 PM
Posted To: database
Conversation: ADO Project
Subject: Re: ADO Project

No, this isn't the exact code but I thought it would be enough to
illustrate
the problem. It seems that VC6 can't find the declarations for
_ConnectionPtr (or any of the other ADO objects)... even though the IDE
editor knows these objects exist and shows tooltips with the correct
methods
and parameters. I have the April 2000 MSDN installed so I'll pick up the
July edition to see if it has any other information.



> If this is the xact code snippet, it looks like you forgot to
initialize
the
> COM object with CoInitialize(NULL); and at the end of WinMain() you
should
use
> CoUninitialize();.
> WinMain() {
>     CoInitialize(NULL);

>     ... All the stuff you want to do...

>     ::CoUninitialize();
> }

> I'm not expert, but what I gather from the documentation is the COM
object
must
> be initialized before any calls to the Library functions.  If you are
going to
> be doing a lot of work with ADO and you don't have the July MSDN, I
would
> suggest picking it up.  It's very thorough.


> > Can someone enlighten me as to what I am doing wrong with this code?
I'm
> > attempting create a simple executable using ADO 2.5. At this point
the
code
> > doesn't do anything other than declare a connection and open it. I
can
tell
> > VC6 resolves the import correctly because I can see all of the
methods
and
> > properties pop up while typing the code. Unfortunately it throws an
error
> > about an undefined reference to _ConnectionPtr when I compile the
code.

> > #import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

> > WinMain()
> > {
> >     _ConnectionPtr pConnection = NULL;
> >     hResult = pConnection.CreateInstance("ADODB.Connection");
> >     pConnection->Open("Provider=SQLOLEDB;Data Source=testsrv;Initial
> > Catalog=Northwind;User ID=sa;Password=;", "", "", NULL);
> >     pConnection->Close();
> > }



Fri, 07 Mar 2003 03:00:00 GMT  
 ADO Project

Quote:
> I created a new simple Win32 console application project, stuck your
> code (see below, it's slightly modified to use main and declaring the
> HRESULT) and it compiled and linked fine.

> Of course, it won't run because it doesn't include ::CoInitialize and my
> server uses another name, but I'd say your problem lies in some other
> part of your code.

> /Martin

> // simpleado.cpp : Defines the entry point for the console application.
> //

> #include "stdafx.h"
> #import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

> int main(int argc, char* argv[])
> {

>     _ConnectionPtr pConnection = NULL;
>     HRESULT hResult = pConnection.CreateInstance("ADODB.Connection");
>     pConnection->Open("Provider=SQLOLEDB;Data Source=testsrv;Initial
> Catalog=Northwind;User ID=sa;Password=;", "", "", NULL);
>     pConnection->Close();
> return 0;
> }

> --------------------Configuration: simpleado - Win32
> Debug--------------------
> Compiling...
> simpleado.cpp
> Linking...

> simpleado.exe - 0 error(s), 0 warning(s)

Thanks for the feedback, Martin. I couldn't find anything wrong with the
code (in either the COM component or the simple application) and kept
banging my head against a wall. I finally tried the same code on another
computer and it compiled fine. Assuming it must be something wrong in my
installation, I broke down and reinstalled Windows 2000 and Visual Studio 6
from scratch and it's working fine now.


Mon, 17 Mar 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ADO In ATL Project,ADO Version,CreateInstance Failed

2. ADO Interface params in attributed project (VC7)

3. Adding ADO support in ATL project

4. Compacting/repairing database through ADO interface in a VC++ project

5. Compact/Repair database through ADO interface in MFC project

6. ADO/ADOCE in one VC++ project? Need advice :-)

7. ADO.NET sure is long-winded compared to old ADO

8. how to display data source in several pages in ado.net like i do in ado

9. Much ADO about nothing?--Oracle BLOBs and ADO 2.0

10. ODBC-SDK, DAO, ADO ? // ADO: doc, version

11. ADO Data control bind to ADO DataGrid

12. Using ADO 2.1 / ADOX / ADO 2.0 with C++

 

 
Powered by phpBB® Forum Software