Ok, I have a MySQL server 5.1 community edition setup on my computer, and I have SQL/ODBC connector 5.1 installed. Now I want to take my C++ console app and be able to connect to my sql server. Yes I have looked through many tutorials and source code and I get hundreds of compiler errors. I am really lost with it now. If someone could give me a link to a good C++ ODBC connection tutorial that works with GNU GCC compiler that would be great.

Thanks. all help appreciated.

what is your operating system ? *nix, MS-Windows, or something else ?

And what tutorial did you attempt to compile ? (link please).

my operating system is windows xp(media center edition) and the main tutorial I tried was the link below, just wondering If someone has one that actually works or can explain how this one works, if I am doing it wrong.


What's your specific problem, any error messages? did you create all needed handles (SQL_HANDLE_ENV, SQL_HANDLE_DBC, SQL_HANDLE_STMD) properly. did you figure out correct connection string for SQL Server? Every function from ODBC interface returns a value what you may check against SQL_SUCCESS. Did you set up your data source properly? You know, that you can configure a data source, for example DSN, that a very detailed log file will be written, what contains a description of every error happened during connection, sql execution etc. You can post your c++ code showing db connection, connection string, open, sql operations etc.


I was getting at least 100 errors when I followed that tutorial, I think I had everything in the wrong order. Could someone go to that link and post the code in an example for C++. Something simple, I just need to see a small working example to learn from it because I am completely lost on what goes where now.

Well, I can do but don't like to do that. Why not reacting to my suggestions first? Also, if one gets at least 100 errors, wouldn't it be great to post some of them?


Without seeing the code you wrote, my guess is that you didn't include windows.h

#include <windows.h>
#include <myheader.h>
#include <sql.h>

int main()
    SQLHANDLE hdlEnv;
    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); 


The trick is to code only a couple lines at a time then compile to see your errors. That makes the errors a lot easier to resolve.

IMO that is not a very good tutorial because it lacks a lot of stuff. Here is a better and more thorough tutorial.

ok thanks Ill take your tips, the tutorial you posted is in C not C++ though.

C and C++ tutorials are identical. There are, however, some ODBC c++ classes that you can download that will help you once you understand how ODBC works.

ok, ill give it a shot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.