Lost connection to MySQL server during query
Posted by:
s s
Date: September 17, 2020 02:48AM
Hi all,
Recently I trying to using connector cpp 1.1.7 to access mysql server(both os is Debian stretch),but encounter "Lost connection to MySQL server during query" problem.It happens when i using transaction, my transaction code looks like :
bool ExecTransaction(const std::vector<std::string>& sqls) {
sql::Statement* statement = nullptr;
sql::Connection* conn = nullptr;
conn = GetConnection();
// for simple, delete code is not written here
try {
conn->setSchema(schema);
statement = conn->createStatement();
conn->setAutoCommit(false);
for (auto& sql : sqls) {
statement->execute(sql);
}
conn->commit();
return true;
} catch (sql::SQLException& e) {
goto rollback;
} catch (std::runtime_error& e) {
goto rollback;
}
rollback:
try {
conn->rollback();
return false;
} catch (sql::SQLException& e) {
return false;
} catch (std::runtime_error& e) {
return false;
}
}
Is there any problem here?Why this problem won't happen if i don't use transaction.
Subject
Views
Written By
Posted
Lost connection to MySQL server during query
4214
September 17, 2020 02:48AM
986
September 17, 2020 11:56AM
1132
September 17, 2020 08:26PM
781
September 18, 2020 09:06AM
818
September 19, 2020 08:20PM
940
September 19, 2020 11:43PM
943
September 20, 2020 08:02PM
867
September 20, 2020 09:56PM
760
September 21, 2020 03:50AM
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.