Solved

ODBC connection in c++

Posted on 2003-11-04
12
513 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

747 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

13 Experts available now in Live!

Get 1:1 Help Now