Closed. This question is
off-topic。它当前不接受答案。
想改善这个问题吗?
Update the question,所以它是
on-topic,用于堆栈溢出。
5年前关闭。
我一直在几个地方寻找此错误,我发现的唯一发现可能是一个野生指针问题,但不知道如何解决。
问题是c ++连接器可以正常工作(在努力工作之后),可以连接到mysql数据库,检索信息,但是每次使用字符串或sqlstring类型时,它都会崩溃,(因此我无法从记录集中获取信息),并出现相同的错误:
0x5e477a8b处不受控制的异常
(msvcp90d.dll)访问冲突
读取存储器位置为0x00445355。
这是我正在使用的代码:
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);
}
任何建议/评论都将得到很好的答复!
因此,这里的调用栈在错误点:
msvcr90d.dll!memcpy(unsigned char * dst = 0x0031fa14,unsigned char * src = 0x00445355,unsigned long count = 0x0000000f)Línea314 Asm
msvcr90d.dll!
msvcp90d.dll!std :: char_traits :: _ Copy_s(char * _First1 = 0x0031fa14,unsigned int _Size_in_bytes = 0x0000000f,const char * _First2 = 0x00445355,unsigned int _Count = 0x0000000f)利纳582 + 0x16字节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 ......形式Línea714 + 0x15字节C ++
msvcp90d.dll!std :: _ Traits_helper :: copy_s>(char * _First1 = 0x0031fa14,unsigned int _Size = 0x0000000f,const char * _First2 = 0x00445355,unsigned int _Count = 0x0000000f)Línea706 + 0x22字节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)利纳1067 + 0x25字节C ++
msvcp90d.dll!std :: basic_string,std :: allocator> :: assign(const std :: basic_string,std :: allocator>&_Right =erróneo)Línea1052 C ++
testMySQL.exe!wmain(int argc = 0x00000001,wchar_t * * argv = 0x00834a30)Línea61 + 0x8d字节C ++
testMySQL.exe!__ tmainCRTStartup()Línea579 + 0x19字节C
testMySQL.exe!wmainCRTStartup()尼斯399 C
kernel32.dll!77391194()
[Los marcos siguientes pueden no sercorrectos o faltar,no se han cargadosímbolospara kernel32.dll]
ntdll.dll!77c7b495()
ntdll.dll!77c7b468()