Solved

ODBC connection in c++

Posted on 2003-11-04
12
519 Views
Last Modified: 2007-12-19
How can make odbc connection and use ADO in c++? Please give me a simple example or point me to the right document.
Any comments is really appreciated.
0
Comment
Question by:prokni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
12 Comments
 
LVL 9

Expert Comment

by:_ys_
ID: 9681420
Start with the following.

// utilise ado 2.6
#import "msado15.dll" named_guids
// full path is required - shouldn't be too hard to find

This will allow you to access the ADO objects utilising standard COM.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9681436
BTW, the typical path is

C:\Program Files\Common Files\System\Ado
0
 
LVL 2

Author Comment

by:prokni
ID: 9682329
any sample code? Even simple one t connect t one access db and insert one record in a table?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:_ys_
ID: 9685464
Sorry, but I don't even have a C++ compiler installed at the moment.
0
 
LVL 1

Expert Comment

by:jploeg
ID: 9685713
0
 
LVL 3

Expert Comment

by:Madz
ID: 9686476
Do you want to use ODBC or ADO?

For pure ODBC level calls,
Use SQLAllocHandle to get an environment pointer. Then, use SQLSetEnvAttr to set the ODBC version on the environment. Use SQLAllocHandle to allocate the database handle, SQLConnect to create a DB connection.

Then create a STMT handle using SQLAllocHandle. SQLPrepare prepares the STMT handle with whatever query you want to execute. Then, SQLExecute exeutes that query.

You will get the documentation for the APIs in MSDN

Madz
0
 
LVL 2

Author Comment

by:prokni
ID: 9687550
I though ADO uses ODBC connection to make a call. Then maybe it is different in c++. WHat about ADO?
0
 
LVL 3

Accepted Solution

by:
Madz earned 50 total points
ID: 9693364
// You can get the clsid using #import "msado15.dll" named_guids
HRESULT hr = spADOConnection.CoCreateInstance(CLSID_CADOConnection);

hr = spADOConnection->put_Mode(adModeReadWrite);
hr = spADOConnection->put_CommandTimeout(1000);

//Create your connection string
hr = spADOConnection->Open(cbstrConnectionString, NULL, NULL, adConnectUnspecified);

//Set your query in pwszQuery
hr = spADOConnection->Execute(CComBSTR(pwszQuery), &svarRecordsAffected, adCmdText, &spADORecordSet);

Madz
0
 
LVL 3

Expert Comment

by:Madz
ID: 10152702
Well, I certainly do have problems with leaving the question unanswered. prokni has said that he/she cannot test the answer suggested. So, I would expect that he/she would post the problems that were encountered while testing the suggested solution. Without any intimations from both sides, how can one expect the appropriate solution to be arrived at?

I agree that simply accepting the answer would prove wrong in that it would be misleading in the future for others. But, I am suprised that the need to arrive at the solution is driven by the needs of the enterprise and not by personal will. I strongly object to the point that the question is now invalid because the requirements at the questioner's end have changed. Rest is up to the moderator.

Madz
0
 
LVL 2

Author Comment

by:prokni
ID: 10156540
Madz
I am not agree with this part of your comment
>>But, I am suprised that the need to arrive at the solution is driven by the needs of the enterprise and not by personal will.
This is the reality in our life. Personal will does not matter at all!!
I agree with the rest.

I am open for any suggestion from moderator. I am willing to give the complete points to Madz in anyway that is possible without misleading others.

Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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