Solved

ODBC connection in c++

Posted on 2003-11-04
12
517 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

789 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