MySQL Forums
Forum List  »  Connector/C++

Re: How do I get the session state (and then reconnect)?
Posted by: Luis Silva
Date: June 21, 2021 08:57AM


Your best option is to use the Client class (pool implementation) and get the session just when you need it. It will keep the session open (see client timeout options) and, when getting the session, it will check if the connection is still open and, if not, do a new connection.

Here is a sample:

ClientSettings settings(SessionOption::HOST,"my_host",
SessionOption::PORT, 33060,
SessionOption::USER, "my_user"

Client client(settings);

for(int i=0; i<10; ++i)

Session s(client);

SqlResult res = s.sql("select @@version").execute();
for(auto row : res)
std::cout << row[0] << std::endl;

//This will timeout the session (controlled by mysqlx_wait_timeout server variable)


Hope this helps!

Luís Silva

Options: ReplyQuote

Written By
Re: How do I get the session state (and then reconnect)?
June 21, 2021 08:57AM

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.