MySQL Forums
Forum List  »  Connector/C++

Unhandled exception while making a small Connector C++ in VS 2010
Posted by: Alvin Revilas
Date: February 13, 2012 05:36PM

Dear Connector C++ experts,

Okay, here is the setup of what I want to do.

Problem Introduction:
I wish to eventually write c++ programs that will connect to a remote server and get appropriately error free responses. Currently I am just
trying to run a simple program that will print out a single result string, from what should be one line from a result set.

Software Being Used:
Microsoft Visual Studio 2010
Downloaded precompiled binaries (*.msi files) of MySQL Workbench and Connector C++, C, and ODBC
Downloaded zip files (called "noinstall" on the MySQL for a reason unknown to me) for Connector C++, C, and ODBC

The Test Database:
The database schema I am using is tAlvin01, the table being referenced is named curAC, and I am trying to access fields 3 and 4 as strings.
There are at least 10 entries in this table, so it is not empty. I would rather access fields 3 and 4 by their field names,
"acMdNum" and "acName", but my debugging efforts have forced me to go this route, and barely gets me some results back,
but with such results mixed with some bad stuff, to be mentioned below.

The source code in question:
It has been created using some modified code from various sample sites, including:

http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html
http://blog.ulf-wendel.de/?p=215

//-------------------begin Alvin's source code-------------------//

/* Copyright 2008, 2010, Oracle and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

There are special exceptions to the terms and conditions of the GPL
as it is applied to this software. View the full text of the
exception in file EXCEPTIONS-CONNECTOR-C++ in the directory of this
software distribution.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/


/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/

#include <mysql_connection.h>
#include <mysql_driver.h>

#include <cppconn/driver.h>
#include <cppconn/connection.h>
#include <cppconn/statement.h>
#include <cppconn/resultset.h>
#include <cppconn/exception.h>
#include <cppconn/warning.h>

using namespace std;

int main(void)
{
char someResponse;


try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;

/* Create a connection */
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("localhost:3306", "root", "my1word");
/* Connect to the MySQL test database */
con->setSchema("talvin01");

stmt = con->createStatement();

res = stmt->executeQuery("SELECT * FROM curAC;");
while (res->next())
{
cout << res->getString(3) << " " << res->getString(4) << endl;
}

delete res;
delete stmt;
delete con;

} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}

cout << "Type in exit and press the enter key to end the program: ";
cin >> someResponse;
return EXIT_SUCCESS;
}

//--------------------end Alvin's source code--------------------//


And now the problem...
This does compile and build inside VS2010, but when I press the green arrow button to run in debug mode, I
get a popup window that has the message:

Unhandled exception at 0x59efad7a (msvcp100d.dll) in test01.exe: 0xC0000005: Access violation reading location 0xccccccd0.

Below is the debug output from the Output window:

//-------------------begin Alvin's program output-------------------//
'test01.exe': Loaded 'C:\mySQL_CPP\testWorkMachine01\Debug\test01.exe', Symbols loaded.
'test01.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\mySQL_CPP\testWorkMachine01\test01\mysqlcppconn.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\mySQL_CPP\testWorkMachine01\test01\libmysql.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\secur32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcp90.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'test01.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'test01.exe': Loaded 'C:\Windows\SysWOW64\nlaapi.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\NapiNSP.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\pnrpnsp.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\mswsock.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\dnsapi.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\winrnr.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Program Files (x86)\Common Files\microsoft shared\Windows Live\WLIDNSP.DLL', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\rasadhlp.dll', Cannot find or open the PDB file
'test01.exe': Loaded 'C:\Windows\SysWOW64\WSHTCPIP.DLL', Cannot find or open the PDB file
First-chance exception at 0x59efad7a (msvcp100d.dll) in test01.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x59efad7a (msvcp100d.dll) in test01.exe: 0xC0000005: Access violation reading location 0xccccccd0.
The program '[2544] test01.exe: Native' has exited with code -1073741819 (0xc0000005).
//--------------------end Alvin's program output--------------------//

I'm not quite sure where to begin to fix this. I hope I don't have to recompile Connector header files or even MySQL files, because I do not have much experience in compiling header files, much less have a proper clue of where to begin such an ugly task.

Please let me know if I am missing any information that may be relevant.

Thanks,
Alvin

Options: ReplyQuote


Subject
Views
Written By
Posted
Unhandled exception while making a small Connector C++ in VS 2010
4730
February 13, 2012 05:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.