MySQL Forums
Forum List  »  Connector/C++

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.

Options: ReplyQuote


Subject
Views
Written By
Posted
Lost connection to MySQL server during query
395
s s
September 17, 2020 02:48AM
157
s s
September 17, 2020 08:26PM
113
s s
September 19, 2020 08:20PM
100
s s
September 20, 2020 08:02PM


Sorry, only registered users may post in this forum.

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.