954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ connect to SQL Server

Hi,
I'm writing a C++ script and part of it is to connect to an SQL Server. C++ is new to me so I'm still working my way around.
Any help would be greatly appreciated.

Many Thanks

sofia24
Newbie Poster
7 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

the easiest way would be to use a library. eg. http://www.sqlapi.com/

vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

how to connect c++ with sql

raj thakur
Newbie Poster
1 post since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

* Simple C program that connects to MySQL Database server*/
#include

#include

main() {

MYSQL *conn;
MYSQL_RES *res;

MYSQL_ROW row;

char *server = "localhost";

char *user = "root";

char *password = "PASSWORD"; /* set me first */

char *database = "mysql";


conn = mysql_init(NULL);


/* Connect to database */
if (!mysql_real_connect(conn, server,

user, password, database, 0, NULL, 0)) {

fprintf(stderr, "%s\n", mysql_error(conn));

exit(1);

}

/* send SQL query */
if (mysql_query(conn, "show tables")) {

fprintf(stderr, "%s\n", mysql_error(conn));

exit(1);
}


res = mysql_use_result(conn);


/* output table name */
printf("MySQL Tables in mysql database:\n");

while ((row = mysql_fetch_row(res)) != NULL)

printf("%s \n", row[0]);


/* close connection */
mysql_free_result(res);

mysql_close(conn);
}

ABID IMRAN
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

nice but too many user mistake in syntax

66vin66
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 


what about ODBC? Google will five you a quick example and explanations

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You