MySQL Forums
Forum List  »  Connector/C++

connecting to MySql server using Visual Studio 2013 Unhandled Exception
Posted by: Mott Matt
Date: June 17, 2015 03:34AM

After trawling the web for hours on end to run a program that using the MySql C++ connector library, I finally managed it. But all of a sudden, with no changes to the project's `Properties`, file paths/locations/names, I am now getting the exception of:

> Unhandled exception at 0x7278AF68 (msvcr90.dll) in MySqlTest.exe: 0xC0000005: Access violation reading location 0x736F686C.

Which in `Release` mode occurs on the line:

con = driver->connect("tcp://127.0.0.1:3306", "localhost", "")

and in `Debug` mode on this line:

std::cout << res->getString("_message") << std::endl;

The only change I made was to try and `INSERT` a value into a table as a test. It didn't work, but when I tried to retrace my steps, the exception shown above started appearing.

The code that I am using (that ran initially) is from the MySql Usage Exmaple 1 (http://dev.mysql.com/doc/connector-cpp/en/connector-cpp-examples-complete-example-1.html):


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

int main()
{
std::cout << "Running 'SELECT 'Hello World!' AS _message'..." << std::endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "localhost", "");
/* Connect to the MySQL test database */
con->setSchema("test");

stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
std::cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
std::cout << res->getString("_message") << std::endl;
std::cout << "\t... MySQL says it again: ";
/* Access column fata by numeric offset, 1 is the first column */
std::cout << res->getString(1) << std::endl;
}
delete res;
delete stmt;
delete con;
}
catch (sql::SQLException &e) {
std::cout << "# ERR: SQLException in " << __FILE__;
std::cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << std::endl;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
}
return EXIT_SUCCESS;
}

Anyone know what is the issue here? I've had 2 days worth of pain regarding trying to get this to work already...

Options: ReplyQuote


Subject
Views
Written By
Posted
connecting to MySql server using Visual Studio 2013 Unhandled Exception
3071
June 17, 2015 03:34AM


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.