I am trying to build a simple MySQL db application in VC++ and have run into a slight problem.
I am using MySQL Connector C++ 1.1.0 and Visual Studio 2012 (Premium if that matters)
<code>
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
/* MySQL Connector/C++ specific headers */
#include <driver.h>
#include <connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>
#include "mysql_driver.h"
#include "mysql_connection.h"
#define DBHOST "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "root"
#define DATABASE "test"
using namespace std;
using namespace sql;
int _tmain(int argc, char *argv[]){
// I'm alive
cout << "Hello World!" << endl;
// necessary variables
Driver *driver;
Connection* con;
Statement *stmt;
ResultSet *res;
/*PreparedStatement *prep_stmt;
Savepoint *savept;*/
//
driver = get_driver_instance();
// Connect to DB
con = driver->connect("tcp//127.0.0.1:3306", "root", "root");
//
con->setAutoCommit(false);
// set schema
con->setSchema("world");
// create statement object
stmt = con->createStatement();
// alert user
cout << "Executing query: \"SELECT * FROM city\"" << endl;
// execute query "SELECT * FROM city"
res = stmt->executeQuery("SELECT * FROM city");
// alert user
cout << "\tRetrieved " << res->rowsCount() << " row(s)." << endl;
// fetch data
while(res->next()){
cout << res->getString("Name") << endl;
}
system("pause");
// Clean up
delete res;
delete stmt;
/*delete prep_stmt;*/
con->close();
delete con;
return 0;
} // end main
</code>
I am building this as a Win32 console application in Release mode, changed the configuration to x64 and have moved mysqlcppconn.dll to the output directory. The code is building correctly (*I think I have correctly added the necessary include directories as well as additional library dependencies/relevant paths). However, when I try to run it I get the following debug output:
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\RBanerjee\Documents\Visual Studio 2012\Projects\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\RBanerjee\Documents\Visual Studio 2012\Projects\ConsoleApplication1\x64\Debug\mysqlcppconn.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\libmysql.dll'. Module was built without symbols.
'ConsoleApplication1.exe' (Win32): Unloaded 'C:\Windows\System32\libmysql.dll'
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\libmysql.dll'. Module was built without symbols.
'ConsoleApplication1.exe' (Win32): Unloaded 'C:\Windows\System32\libmysql.dll'
The program '[4172] ConsoleApplication1.exe' has exited with code -1073741701 (0xc000007b).
I am a little lost as to what to do next, I really just want to be able to develop a Windows application that can connect to a MySQL db and interact with it. I would appreciate any help with this problem or a pointer to some other tutorial.
Thanks
I am using MySQL Connector C++ 1.1.0 and Visual Studio 2012 (Premium if that matters)
<code>
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
/* MySQL Connector/C++ specific headers */
#include <driver.h>
#include <connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>
#include "mysql_driver.h"
#include "mysql_connection.h"
#define DBHOST "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "root"
#define DATABASE "test"
using namespace std;
using namespace sql;
int _tmain(int argc, char *argv[]){
// I'm alive
cout << "Hello World!" << endl;
// necessary variables
Driver *driver;
Connection* con;
Statement *stmt;
ResultSet *res;
/*PreparedStatement *prep_stmt;
Savepoint *savept;*/
//
driver = get_driver_instance();
// Connect to DB
con = driver->connect("tcp//127.0.0.1:3306", "root", "root");
//
con->setAutoCommit(false);
// set schema
con->setSchema("world");
// create statement object
stmt = con->createStatement();
// alert user
cout << "Executing query: \"SELECT * FROM city\"" << endl;
// execute query "SELECT * FROM city"
res = stmt->executeQuery("SELECT * FROM city");
// alert user
cout << "\tRetrieved " << res->rowsCount() << " row(s)." << endl;
// fetch data
while(res->next()){
cout << res->getString("Name") << endl;
}
system("pause");
// Clean up
delete res;
delete stmt;
/*delete prep_stmt;*/
con->close();
delete con;
return 0;
} // end main
</code>
I am building this as a Win32 console application in Release mode, changed the configuration to x64 and have moved mysqlcppconn.dll to the output directory. The code is building correctly (*I think I have correctly added the necessary include directories as well as additional library dependencies/relevant paths). However, when I try to run it I get the following debug output:
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\RBanerjee\Documents\Visual Studio 2012\Projects\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\RBanerjee\Documents\Visual Studio 2012\Projects\ConsoleApplication1\x64\Debug\mysqlcppconn.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\libmysql.dll'. Module was built without symbols.
'ConsoleApplication1.exe' (Win32): Unloaded 'C:\Windows\System32\libmysql.dll'
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\libmysql.dll'. Module was built without symbols.
'ConsoleApplication1.exe' (Win32): Unloaded 'C:\Windows\System32\libmysql.dll'
The program '[4172] ConsoleApplication1.exe' has exited with code -1073741701 (0xc000007b).
I am a little lost as to what to do next, I really just want to be able to develop a Windows application that can connect to a MySQL db and interact with it. I would appreciate any help with this problem or a pointer to some other tutorial.
Thanks