Database Connections in Windows Program

Hi, I'm currently working on a program that needs to access information from a database. I posted a similar question to the "General C++" forum, but it got a resounding 0 replies possibly because I posted it to the wrong forum since it regarded a program heavily invested in Windows API and connection to Windows servers.

The problem I'm having is that I have no idea where to begin trying to establish a database connection from my program so that I can make SQL commands despite viewing multiple sources which all tell me to go in completely different directions. I was hoping someone would be able to do a quick "How to:" summary for me or at least point me in the right direction. Thanks in advance!
What type of database are you using?

if you are building one from scratch i would recommend using mysql they have good documentation and it is quite easy to understand.

http://dev.mysql.com/downloads/connector/cpp/#downloads

i think you would require to build the files with cmake and need boost library.
I'm using a premade Microsoft SQL Server 2005 database. I was hoping to use the features that already come with Visual Studio to complete the task (like <sqlext.h>), but I'll certainly take a look at mysql.
I managed to get this before I tried mysql. It fails every time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret;
SQLSMALLINT columns;

       // Allocate an environment handle
	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
	SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);

	// Allocate the connection handle
	SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);

	// Connect to the DSN
	SQLDriverConnectW(dbc, NULL, L"DRIVER={SQL Server};SERVER=(******);
                  DATABASE=**********;UID=******;
                  PWD=******;", SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);
	if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt))
	{
		PostQuitMessage(0);
	}
Topic archived. No new replies allowed.