I've been looking for this error in several places and the only thing I found is maybe is a wild pointer problem, but don't know how to solve.
The question is c++ connector works fine (after hard working) connects to mysql database, retrieves information, but every time that uses string or sqlstring type it crashes, (so I can't get the info from the recordset) with same error:
Not controlled exception at 0x5e477a8b (msvcp90d.dll) access violation when reading memory position at 0x00445355.
Here the code I'm using:
int main() {
Driver *driver;
Connection *con;
Statement *stmt;
ResultSet *res;
string fld;
char *fldName = "divisa";
int row=1, nrows=0;
char *url, *database, *usr, *pw;
url = DBHOST;
database = DATABASE;
usr = getstr("User: ", -1, 128); // char* getstr(char prompt[], char chReplace, int maxLen);
pw = new char[128];
pw = getstr("Password: ", '\0', 128);
cout << endl;
try {
driver = get_driver_instance();
con = driver->connect(url, usr, pw);
pw = new char[128];
con->setAutoCommit(0);
con->setSchema(database);
stmt = con->createStatement();
res = stmt->executeQuery("SELECT * FROM `estglob`");
while(res->next()) {
fld.assign(res->getString(fldName));
cout << fld << endl;
}
_getch();
cout << endl << "Cleaning up the resources .." << endl;
delete res;
delete stmt;
con -> close();
delete con;
}
catch (SQLException &e) {
cout << endl << "ERROR: SQLException in " << __FILE__;
cout << " (" << __FUNCTION__<< ") on line " << __LINE__ << endl;
cout << "ERROR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode() << ")";
cout << ", SQLState: " << e.getSQLState() << ")" << endl; // <== CRASH here
_getch();
return(EXIT_FAILURE);
}
catch (std::runtime_error &e)
{
cout << "ERROR: runtime_error in " << __FILE__;
cout << " (" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "ERROR: " << e.what() << endl;
_getch();
return(EXIT_FAILURE);
}
return(EXIT_SUCCESS);
}
Any suggestion / comments will be really well recieved!
So here the callstack at error point:
msvcr90d.dll!memcpy(unsigned char * dst=0x0031fa14, unsigned char * src=0x00445355, unsigned long count=0x0000000f) Línea 314 Asm
msvcr90d.dll!memcpy_s(void * dst=0x0031fa14, unsigned int sizeInBytes=0x0000000f, const void * src=0x00445355, unsigned int count=0x0000000f) Línea 67 + 0x11 bytes C
msvcp90d.dll!std::char_traits::_Copy_s(char * _First1=0x0031fa14, unsigned int _Size_in_bytes=0x0000000f, const char * _First2=0x00445355, unsigned int _Count=0x0000000f) Línea 582 + 0x16 bytes C++
msvcp90d.dll!std::_Traits_helper::copy_s >(char * _First1=0x0031fa14, unsigned int _Size=0x0000000f, const char * _First2=0x00445355, unsigned int _Count=0x0000000f, std::_Secure_char_traits_tag __formal={...}) Línea 714 + 0x15 bytes C++
msvcp90d.dll!std::_Traits_helper::copy_s >(char * _First1=0x0031fa14, unsigned int _Size=0x0000000f, const char * _First2=0x00445355, unsigned int _Count=0x0000000f) Línea 706 + 0x22 bytes C++
msvcp90d.dll!std::basic_string,std::allocator >::assign(const std::basic_string,std::allocator > & _Right= erróneo, unsigned int _Roff=0x00000000, unsigned int _Count=0xffffffff) Línea 1067 + 0x25 bytes C++
msvcp90d.dll!std::basic_string,std::allocator >::assign(const std::basic_string,std::allocator > & _Right= erróneo) Línea 1052 C++
testMySQL.exe!wmain(int argc=0x00000001, wchar_t * * argv=0x00834a30) Línea 61 + 0x8d bytes C++
testMySQL.exe!__tmainCRTStartup() Línea 579 + 0x19 bytes C
testMySQL.exe!wmainCRTStartup() Línea 399 C
kernel32.dll!77391194()
[Los marcos siguientes pueden no ser correctos o faltar, no se han cargado símbolos para kernel32.dll]
ntdll.dll!77c7b495()
ntdll.dll!77c7b468()