[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1671
  • Last Modified:

Problem using ADO in C++

Hi,

I am a novice to the C++ world (just trying to write my first C++ program to access a database through ADO).

I have written a header file database.h with the following lines of code:
//database.h
#import "c:\Program Files\Common Files\System\ADO\msado15.dll"
     no_namespace rename("EOF", "adoEOF")
typedef ADODB::_RecordsetPtr  RecPtr;
typedef ADODB::_ConnectionPtr CnnPtr;

I have added this header file to a Hello World Project which, I have generated through the AppWizard. The idea is to modify the same main function to use ADO and open a DB connection.

However, on compilation, I got the same error (error C2238: unexpected token(s) preceding ';). Refering to the solution suggested by Mirec in one of the questions, I added the import statement for msado20.tlb. The code now looks as below:

//Modified database.h
#undef EOF
#import "c:\Program Files\Common Files\System\ADO\msado15.dll"
     no_namespace rename("EOF", "adoEOF")
#import "c:\Program Files\Common Files\System\ADO\msado20.tlb"
     no_namespace rename("EOF", "adoEOF")
typedef ADODB::_RecordsetPtr  RecPtr;
typedef ADODB::_ConnectionPtr CnnPtr;

However, still I am getting the below error: Can you please help?

d:\c++\ado2\debug\msado15.tlh(409) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
d:\c++\ado2\database.h(3) : error C2146: syntax error : missing ';' before identifier 'rename'
d:\c++\ado2\database.h(3) : error C2501: 'no_namespace' : missing storage-class or type specifiers
d:\c++\ado2\database.h(3) : fatal error C1004: unexpected end of file found

Thanks in advance for your answer,
-Yj
0
itsavvy_yj
Asked:
itsavvy_yj
3 Solutions
 
AndyAinscowCommented:
look at
www.codeproject.com/database/caaadoclass1.asp
that should be off the shelf classes to wrap ADO
0
 
nabehsCommented:
//Try either:

#pragma warning(disable : 4146)

#import "c:\Program Files\Common Files\System\ADO\msado15.dll"  rename("EOF", "adoEOF")

typedef ADODB::_RecordsetPtr  RecPtr;
typedef ADODB::_ConnectionPtr CnnPtr;



// Or try

#pragma warning(disable : 4146)

#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "adoEOF")

typedef _RecordsetPtr  RecPtr;
typedef _ConnectionPtr CnnPtr;


// i put #import statement on one line
// if you specify no_namespace then you dont need ADODB:: before pointers
0
 
itsavvy_yjAuthor Commented:
Hi,

Thanks a lot for your valuable comments. I am now trying to connect to a Oracle Database through the ADODB. However, I am not sure what values I should passs to the Open connection call. The values of the connection string, the provider etc..

Can you please tell me how can I open a connection?

Thanks a ton!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
nabehsCommented:
http://www.connectionstrings.com/

I think it is the same as ole db
0
 
CezariuszCommented:

CnnPtr m_spConn;
m_spConn.CreateInstance(__uuidof(Connection));
// if using standard Oracle client (OCI):
CString strDbName = "connection.name.from.tnsnames.ora";
// if using Oracle Instant Client:
CString strDbName = "//server:port/service";
CString strConnection = "Provider=MSDAORA;Data Source=" + strDbName;
m_spConn->Open(strConnection, strUsername, strPassword, adConnectUnspecified);
0
 
AndyAinscowCommented:
split, all experts
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now