Solved

ODBC connection in c++

Posted on 2003-11-04
12
516 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 147
C++ question 3 65
VS2015 Redefinition errors 4 49
How to convert Structure to vector of byte and vice versa 5 12
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

776 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