Bu hatayı birkaç yerde arıyordum ve bulduğum tek şey belki de vahşi bir işaretçidir, ancak nasıl çözüleceğini bilmiyorum.C++ mysql sqlstring çöküyor 0xC0000005 belleği okuyamadı
Soru C++ bağlayıcı çalışıyor (sıkı çalıştıktan sonra) mysql veritabanına bağlanır, bilgi alır, ancak bu her zaman kilitlenir dize veya sqlstring türünü kullanır, (bu yüzden bilgileri kayıt kümesinden alamıyorum) İşte
Not controlled exception at 0x5e477a8b (msvcp90d.dll) access violation when reading memory position at 0x00445355.
kullanıyorum kodu: aynı hata
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);
}
Herhangi bir öneri/yorum gerçekten iyi alınan olacak! Yani burada
hata noktasında callstack:
msvcr90d.dll memcpy (unsigned char * dst = 0x0031fa14, işaretsiz char * src = 0x00445355, imzasız uzun sayısı = 0x0000000f) Línea 314 makina dili
msvcr90d.dll! memcpy_s (void * dst = 0x0031fa14, imzasız int sizeInBytes = 0x0000000f, void * src = 0x00445355, imzasız int adet = 0x0000000f) Línea 67 + 0x11 bayt C
msvcp90d.dll! std :: char_traits :: _ Copy_s (char * _First1 = 0x0031fa14, imzasız int _Size _Size = int _in_bytes = 0x0000000f, const char * _First2 = 0x00445355, imzasız int _Count = 0x0000000f) Línea 582 + 0x16 bayt C++
msvcp90d.dll! Std :: _ Traits_helper :: copy_s> (char * _First1 = 0x0031fa14, imzasız 0x0000000f, const char * _First2 = 0x00445355, imzasız int _Count = 0x0000000f, std :: _ Secure_char_traits_tag __formal = {...}) Línea 714 + 0x15 bayt C++
msvcp90d.dll! std :: _ Traits_helper :: copy_s> (Char * _First1 = _Size = 0x0000000f int işaretsiz 0x0031fa14, const char * _First2 = 0x00445355, imzasız int _Count = 0x0000000f) Línea 706 + 0x22 bayt C++
msvcp90d.dll std :: basic_string, std :: allocator>!: : atama (const std :: basic_string, std :: a llocator> & _Right = erróneo, imzasız int _Roff = 0x00000000, imzasız int _Count = 0xffffffff) Línea 1067 + 0x25 bayt C++
msvcp90d.dll std :: basic_string, std :: allocator> :: atamak (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 bayt C++
testMySQL!. exe! __ tmainCRTStartup() Línea 579 + 0x19 bayt C
testMySQL.exe! wmainCRTStartup() Líne 399 ° C
kernel32.dll! 77391194()
[Los marcos siguientes correctos O faltar, no se han cargado símbolos para kernel32.dll bir ser pueden]
ntdll.dll! 77c7b495()
ntdll.dll! 77c7b468()
Bir milyon teşekkürler! Fld = res-> getString (fldName) .c_str() ile çözüldü; – Miquel
Sadece hangi derleyiciyi kullandığınızı referans olarak kabul edersiniz. –
netbeans & cygwin kullanmaya başladım ama windows entegrasyonu nedeniyle ms visual C++ 'ye taşındım – Miquel