Skip to main content
gamedev.net
🔒 Locked

C++ and SQL Server

Started by kokigfc Oct 19, 2005 at 2:15 PM 5 replies 600+ views
Original Post
kokigfc
kokigfc
I need to do a c++ application which will connect to a database (I'm using Microsoft SQL Server). How can i do this? Any idea? Thanks, Gustavo.
dbh
dbh
Curator Defense is written in C++ and communicates via the HTTP protocol with a PHP script I wrote on my domain.

That PHP script logs in to the MySQL server (it is on the same domain, but doesn't have to be) and authenticates the user. Then, assuming authentication completes, it inserts the provided data that was sent into the database.

I am then sending a message back to the application to let them know the score submission worked, didn't work, their old score was higher, bad password, whatever.

This doesn't allow for complex client/server communication, but it works great for my purposes.

The other option is the MySQL C Library to communicate directly with the MySQL server you have setup. Depending on your needs, this can be good or bad. If you are trying to write a client application that needs to communicate with your server (in other words, ANY computer from ANYWHERE in the world is a possible client at one point or another), this is a bad idea. Most college campuses (and many ISPs) block the MySQL port. That's why I am using a PHP script to serve as a proxy between the two.

Hope this helps...
-dbh
------------------------------------------------------------GDC/IGF 2006 Student Showcase Submission: Curator Defense
rmsimpson
rmsimpson
That depends ... is the C++ program running in Windows? Are you using a MS compiler?

For Windows, your options are OLEDB, ODBC or ADO. For other platforms you can use ODBC, provided a SQL Server ODBC driver is installed.

If you're using a recent MS compiler, you have access to the OLEDB template library, or can use MFC's ODBC classes. ADO is a COM-based technology that you can also use in Windows.

Robert
Arild Fines
Arild Fines
Quote:
Original post by rmsimpson
That depends ... is the C++ program running in Windows? Are you using a MS compiler?

For Windows, your options are OLEDB, ODBC or ADO.

There's also a "native" C++ library for SQL Server. SQL Server ships with the libs and include files for it, IIRC.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
kokigfc
kokigfc
Thanks for replyies!

Do you know where can i find any tutorial about OLEDB template library, or ODBC?
There's any API to do this?

ps: I'm using MSVC 6.0
rmsimpson
rmsimpson
Quote:
Original post by Arild Fines
There's also a "native" C++ library for SQL Server. SQL Server ships with the libs and include files for it, IIRC.


The native DB-Library of SQL Server is depreciated, unfortunately.

http://msdn.microsoft.com/data/mdac/default.aspx?pull=/library/en-us/dnmdac/html/data_mdacroadmap.asp

If you're comfortable with COM but haven't had any previous database experience, you may find ADO more to your liking. If you are not familiar with COM and don't mind some extra MFC bloat in your code, you can play around with ODBC and MFC's CDatabase and etc classes.

If you want to get as close to the bone as possible and are familiar with template-based programming, you can also use the OLEDB consumer templates.

In my opinion, ODBC is the easiest for someone with no COM or template experience to jump into. The MFC classes make it pretty dead easy to get some SQL code rolling with minimal effort.

Robert
kokigfc
kokigfc
Thanks rmsimpson for yur help.

"In my opinion, ODBC is the easiest for someone with no COM or template experience to jump into. The MFC classes make it pretty dead easy to get some SQL code rolling with minimal effort."

But MFC is complicated, isn't it?
Where can i found a tutorial, or a article about that. I'm lookin for information of ODBC and i can't find nothing...

Thanks very much for your help!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.