Hello
I am trying to connect MySQL database from C++ code given below-
My development environment is -
Window 7
CODE::BLOCKS 10.05 with minGW mingw32-g++.exe
MySQL Connector C++ 1.0.5\lib\debug\mysqlcppconn.lib
Up to compilation and linking every thing is OK I followed the tutorial http://dev.mysql.com/doc/refman/5.1/...example-1.html
Code:
1.#include <stdlib.h>
2.#include <iostream>
3.#include <winsock2.h>
4./*
5.  Include directly the different
6.  headers from cppconn/ and mysql_driver.h + mysql_util.h
7.  (and mysql_connection.h). This will reduce your build time!
8.*/
9.#include "mysql_connection.h"
10.
11.#include <cppconn/driver.h>
12.#include <cppconn/exception.h>
13.#include <cppconn/resultset.h>
14.#include <cppconn/statement.h>
15.
16.using namespace std;
17.int main(void)18.
{
19.cout << endl;
20.cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
21.
22.try {
23.  sql::Driver *driver;
24.  sql::Connection *con;
25.  sql::Statement *stmt;
26.  sql::ResultSet *res;
27.cout << "Running 'SELECT 'Hello World!...1' AS _message'..." << endl;
28.  /* Create a connection */
29.  driver = get_driver_instance();
30.  cout << "Running 'SELECT 'Hello World!...2' AS _message'..." << endl;
31.  con = driver->connect("tcp://127.0.0.1:3306", "root", "");
32.  cout << "Running 'SELECT 'Hello World!...3' AS _message'..." << endl;
33.  /* Connect to the MySQL test database */
34.  con->setSchema("bill");
35.cout << "Running 'SELECT 'Hello World!...1' AS _message'..." << endl;
36.  stmt = con->createStatement();
37.  res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
38.  while (res->next()) {
39.    cout << "\t... MySQL replies: ";
40.    /* Access column data by alias or column name */
41.    cout << res->getString("_message") << endl;
42.    cout << "\t... MySQL says it again: ";
43.    /* Access column fata by numeric offset, 1 is the first column */
44.    cout << res->getString(1) << endl;
45.  }
46.  delete res;
47.  delete stmt;
48.  delete con;
49.
50.} catch (sql::SQLException &e) {
51.  cout << "# ERR: SQLException in " << __FILE__;
52.  cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
53.  cout << "# ERR: " << e.what();
54.  cout << " (MySQL error code: " << e.getErrorCode();
55.  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
56.}
57.
58.cout << endl;
59.return EXIT_SUCCESS;
60.}
When I run the code it shows
SELECT 'Hello World!
SELECT 'Hello World!....1
SELECT 'Hello World!....2
And then Debug window open with a message "bill.exe has stopped working", I copied libmysql.dll to my application debug folder.
My assumption is that line no. 31 is raising problem because after that cout for Hello World!...3 is not executing.

May be require some port or network related file.
Any idea or advice will be great help for me.
Thank you